|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- #include <string.h>
- //************************统计输入的中英文的总个数*************************
- int main()
- {
- char str[100];
- int i = 0,count = -1; //count赋值-1,因为在读取字符串时候发现,字符串结束时的最后一位并不是'\0',下一位才是
- printf("enter a string:");
- gets(str) ;
- printf("*str = %s , *(str + 1) = %s , *(str + 2 ) = %c \n",*str,*(str + 1),*(str + 2));
-
- for(i = 0 ; ; i++)
- {
- if (*(str + i )== '\0')
- {
- break;
- }
- else
- {
- count += 1;
- }
- }
- printf("the lenth of the string is: %d",count);
- }
复制代码
- #include <stdio.h>
- #include <string.h>
- //************************统计输入的中英文的总个数*************************
- int main()
- {
- char str[100];
- int i = 0, count = 0; //count赋值-1,因为在读取字符串时候发现,字符串结束时的最后一位并不是'\0',下一位才是
- printf("enter a string:");
- gets(str);
- printf("*str = %c , *(str + 1) = %c , *(str + 2 ) = %c \n", *str, *(str + 1), *(str + 2));
- for (i = 0; ; i++)
- {
- if (*(str + i) == '\0')
- {
- break;
- }
- else
- {
- count += 1;
- }
- }
- printf("the lenth of the string is: %d", count);
- }
复制代码
|
|