编写一函数len,求一个字符串的长度。要求用字符指针实现。在主函数中输入字符串,调用该len函数后输出其长度。
期末了,有很多不会的,想找一个师傅问问题,会请喝奶茶,谢谢!
void swap(int *a, int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
#include <stdio.h>
int len(char *p);
int main()
{
int a,b,c;
char str[25];
gets(str);
printf("%d",len(str));
}
int len(char *p){
int a = 0;
while(*p != '\0'){
a ++;
p ++;
}
return a;
}