-1
我不能为了我的生活找出为什么我的代码没有产生我需要的输出。要求是不使用任何功能。当我输入一行像“文本”这样的文本时,得到的数组是“tex”,切断了对我来说毫无意义的最后一个字母。接收用户输入并将其存储在一个数组中C
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int read_input(char line_of_text[])
{
int index = 0;
char ch;
// if(!line_of_text[0])
// return index;
for(ch = getchar(); ch != '\n' && ch != '\0'; ch = getchar()){
if(ch == EOF){ //clear string and return EOF
line_of_text[0] = '\0';
return EOF;
}
line_of_text[index++] = ch;
}
line_of_text[++index] = '\0';
return index;
}
'炭CH;' - >'INT CH = 0;'' –
line_of_text [++指数] = '\ 0';' - >'line_of_text [index] ='\ 0 ';' – jiveturkey
为什么在到达EOF时清除了字符串? –