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

初学者啥都不懂一边看书一边提问 多则多则

2012-08-10 
菜鸟啥都不懂一边看书一边提问多则多则就这个程序,#include stdio.h#include string.h#define SIZE 20

菜鸟啥都不懂一边看书一边提问 多则多则
就这个程序,
#include <stdio.h>
#include <string.h>
#define SIZE 20
#define LIM 2
#define STOP "quit"
int main(void)
{
  char input[LIM][SIZE];
  int ct = 0;

  printf("Enter up to %d lines (type quit to quit):\n", LIM);
  while (ct < LIM && gets(input[ct]) != NULL &&
  strcmp(input[ct],STOP) != 0)
  {
  ct++;
  }
  printf("%d strings entered\n", ct);
  
  return 0;
}

这个条件 gets(input[ct]) != NULL 
我们知道:
gets():
原理:一直读取字符直到遇见一个“换行符”,同时在字符串最后生成一个空字符/0,并且丢弃“换行符”.

它使用return关键字返回字符串的地址
函数原型:
char * gets(char *s)
{
...
return (s);
}

我的疑问:在程序运行后如何让 gets(input[ct]) == NULL 。 通过什么操作,我输入了回车 空格 0 ,还是无法满足这个条件
-------------------------------
就像这样:
------------------------------------------------------
Enter up to 2 lines (type quit to quit):


2 strings entered
请按任意键继续. . .
------------------------------------------------------
总而言之 如何利用这个表达式达到和输入quit一样的效果

Enter up to 2 lines (type quit to quit):
quit
0 strings entered
请按任意键继续. . .


[解决办法]
Ctrl+z试试

热点排行