-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時清除了字符串? –