Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C:输入中的无限循环_C_Loops_Stdin - Fatal编程技术网

C:输入中的无限循环

C:输入中的无限循环,c,loops,stdin,C,Loops,Stdin,这是我的函数,问题是 它从不停止在命令行中获取输入。 我想不出哪里是放置返回0的合适行 int my_rot13(int c) { if ('a' <= tolower(c) && tolower(c) <= 'z') return tolower(c)+13 <= 'z' ? c+13 : c-13; return c; } int main() { int k, c; char *p; if (argc &l

这是我的函数,问题是 它从不停止在命令行中获取输入。
我想不出哪里是放置
返回0
的合适行

int my_rot13(int c) {
    if ('a' <= tolower(c) && tolower(c) <= 'z')
        return tolower(c)+13 <= 'z' ? c+13 : c-13;
    return c;
}

int main() {

  int k, c;
  char *p;

  if (argc < 2) {
    while ((c = getc(stdin)) != EOF) {
      putchar(my_rot13(c));  
    }
    return 0; 
  }

  for (k = 1; k < argc; k++) {
    for (p = argv[k]; *p != '\0'; p++) {
      putchar(my_rot13(*p));
    }
    putchar(' ');
  }
  putchar('\n');

  return 0;
}
int my_rot13(int c){

如果('a'如果从标准输入捕获,则使用
'\n'
而不是
EOF
如果从标准输入捕获,则使用
'\n'
而不是
EOF

您需要将字符发送到
getc()
,当您手动键入输入时。您可以在Linux上使用Ctrl-D进行此操作,在Windows上使用Ctrl-Z进行此操作。另一个选项是根据换行符('\n')进行测试。

您需要将字符发送到
getc()
,当您手动键入输入时。您可以在Linux上使用Ctrl-D进行此操作,在Windows上使用Ctrl-Z进行此操作。另一个选项是根据换行符('\n')进行测试。

按Ctrl-D结束输入。(如果您在Windows上,则按Ctrl-Z)或检查
(c=getc(stdin))!='\n'
只接受一行。+1对于格式正确且代码正确的问题,或者,检查是否存在除
EOF
以外的内容。按CTRL-D结束输入。(如果在windows上,则按CTRL-Z)或检查
(c=getc(stdin))!='\n'
只接受一行。+1对于格式良好且代码正确的问题,或者,检查除
EOF