码迷,mamicode.com
首页 > 编程语言 > 详细

喜羊羊系列之数组获取字符串

时间:2015-04-05 13:25:49      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:c语言   字符串   字符串数组   字符串结束   linux   

#define bufsiz 512
  8 #include<stdio.h>
  9 
 10 int main(){
 11     char ch[bufsiz];
 12     int i=0;
 13 
 14     printf("请输入一串字符串 \n");
 15 #if 1
 16     scanf("%s",ch);
 17     do{
 18         printf("%d:%c ",i, ch[i]);
 19     }
 20     while(ch[i++] != '\0');
 21 #else 
 22     while(ch[i++] != '\r'); 
 23     while(ch[i++] != '\n');
 24     while(ch[i++] != 'EOF');
 25 
 26 #endif
 27 
 28 #if 0
 29     gets(ch);
 30     
 31     do{
 32         printf("%d:%c ",i, ch[i]);
 33     }while( ch[i++] != '\0');
 34 #endif
 35 
 36 #if 0
 37     得出,使用gets会将字符串后加 '\0'以表示结束
 38     而 scanf + %s 的形式也是将字符串后面加'\0'来结束,
 39     而不是用'\r', '\n', 'EOF'来表示字符串结束。
 40 #endif
 41     printf("\n""");
 42     return 0;
 43 }

喜羊羊系列之数组获取字符串

标签:c语言   字符串   字符串数组   字符串结束   linux   

原文地址:http://blog.csdn.net/muyang_ren/article/details/44886791

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!