13.c
来自「数据结构练习共18道。」· C语言 代码 · 共 43 行
C
43 行
#include <stdio.h>
#include<malloc.h>
typedef struct node{
char Elem;
struct node *next;
}Lnode;
void main()
{
char k;int len=0;
Lnode *s,*l,*p,*q,*tail;
s =(Lnode*) malloc(sizeof (Lnode));
s->Elem=0;
s->next=NULL;
printf("Input the string:");
k=getchar();
while(k!=(char)(10))
{
p =(Lnode*) malloc(sizeof (Lnode));
p->Elem=k;
p->next=NULL;
if (s->next==NULL)
{
s->next = p;
tail=p;
}
else
{tail->next=p;tail=p;}
k=getchar();
}
p=s->next;
while(p!=NULL)
{
len++;p=p->next;
}
printf("\nThe length of the string is:%d",len);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?