首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C编程初学者-请解释此错误

C编程初学者-请解释此错误
EN

Stack Overflow用户
提问于 2012-05-10 01:28:39
回答 5查看 365关注 0票数 6

我只是从C开始,尝试了Ritchie书中的几个例子。我写了一个小程序来理解字符数组,但偶然发现了一些错误,并希望能对我理解错误的地方有所了解:

代码语言:javascript
复制
#include <stdio.h>
#define ARRAYSIZE 50
#include <string.h>

main () {
  int c,i;
  char letter[ARRAYSIZE];
  i=0;
  while ((c=getchar()) != EOF )
  {    
    letter[i]=c;
    i++;
  }
  letter[i]='\0';
  printf("You entered %d characters\n",i);
  printf("The word is ");

  printf("%s\n",letter);
  printf("The length of string is %d",strlen(letter));
  printf("Splitting the string into chars..\n");
  int j=0;
  for (j=0;j++;(j<=strlen(letter)))
    printf("The letter is %d\n",letter[j]);
}

输出为:

代码语言:javascript
复制
$ ./a.out 
hello how are youYou entered 17 characters
The word is hello how are you
The length of string is 17Splitting the string into chars..

这是怎么回事?为什么for循环没有给出任何输出?

EN

Stack Overflow用户

发布于 2012-05-10 01:31:30

for (j=0;j++;(j<=strlen(letter)))它是不正确的。

它应该是第三个位置的for (j=0; j<=strlen(letter); j++) - increment。

票数 4
EN
查看全部 5 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10521101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档