首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

大姐们帮忙看看为什么这个程序出不来sum值啊

2012-10-06 
各位大哥大姐们帮忙看看为什么这个程序出不来sum值啊?#includestdio.h#includestdlib.hint main(void)

各位大哥大姐们帮忙看看为什么这个程序出不来sum值啊?
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  char sum=-1;
  int c;
  /*
  **Read the characters one by one ,and add them to the sum.
  */

  while ((c=getchar())!=EOF)
  {
putchar(c);
sum+=c;
  }
  printf("%d\n",sum);
return EXIT_SUCCESS;
}

[解决办法]
1、char的范围有限 
2、char sum=-1;//没明白等于-1是什么意思

[解决办法]
我是新手,回答错了请见谅
[解决办法]
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char sum=-1;
int c;
/*
**Read the characters one by one ,and add them to the sum.
*/

while ((c=getchar())!=EOF)
{
putchar(c);
sum+=c;
printf("%d\n",sum);
}

return EXIT_SUCCESS;
}
[解决办法]
我的印象char 0-255.

感觉你的程序中sum 和 c的类型写反了。

你代码中sum+=c;这里存在隐式的类型转换。

热点排行