C语言指针解答:写一个函数,求一个字符串长度,在main函数中输入字符串,并输出其长度

我想请教下,C语言指针解答:写一个函数,求一个字符串长度,在main函数中输入字符串,并输出其长度
最新回答
一清北华

2024-05-03 02:48:43

#include "stdio.h"
#include "string.h"

void main()
{
int len;
char a[100];
printf("输入字符串:");
scanf("%d",a)//或者gets(a);
len=strlen(a);
printf("长度为:%d\n",len);
}
可以了~~~
你瞎啊撞我心上了

2024-05-03 01:44:48

#include <stdio.h>
#define Maxsize 20
int makesize(char *p)
{
int count=0;
while(*p++)
count++;
return count;
}
int main()
{
char name[Maxsize];
printf("输入字符串:\n");
gets(name);
printf("字符串长度是%d",makesize(name));
return;
}
飞花逐水流

2024-05-03 01:42:12

#include <stdio.h>
#include <string.h>

int get_strlen(string *str);
int main()
{
string *str;
int length;
printf("Please input the string:");
scanf("%s",str);
length = get_strlen(*str);
printf("The length of the string is : %d\n",length);
return 0;
}
int get_strlen(string *str)
{
int count = 0;
while(*str)
{
++count;
*str++;
}
return count;
}
没有编译过,不知道能不能编译!
你随我身却伴他心

2024-05-03 02:41:09

#include<stdio.h>
main()
{
int nl;
nl=0;
while(getchar()!=EOF)
nl++
printf("%d",nl);
}