我寫這是會讀dictionnary語法如下的程序:線的多個終端刪除
john
philips
dudule
henry
因此,我寫了這個程序:
#define SIZEWORD 10
int main (int argc, char **argv)
{
/*get dictionarry words*/
FILE * pFile_dictionnary;
char dictionarry_name[SIZEWORD];
int len;
pFile_dictionnary = fopen (argv[1] , "r");
if (pFile_dictionnary == NULL) perror ("Error while opening the dictionnary");
else
{
while (!feof (pFile_dictionnary))
{
if (fgets (dictionarry_name , SIZEWORD , pFile_dictionnary) == NULL) break;
printf("Before : dictionarry_name is = [%s] \n", dictionarry_name);
/*remove new line*/
char *tmp_LF = strrchr(dictionarry_name, '\n');
if(tmp_LF != NULL)*tmp_LF = '\0';
printf("After : dictionarry_name is = [%s] \n", dictionarry_name);
}
}
fclose (pFile_dictionnary);
return 0;
}
有人能解釋對我來說爲什麼我有這個輸出?我試圖消除由與fgets函數添加了新的生產線,但它似乎沒有任何效果:
Before : dictionarry_name is = [john
]
After : dictionarry_name is = [john
]
Before : dictionarry_name is = [philips
]
After : dictionarry_name is = [philips
]
Before : dictionarry_name is = [dudule
]
After : dictionarry_name is = [dudule
]
Before : dictionarry_name is = [henry
]
After : dictionarry_name is = [henry
]
感謝您的幫助
PS:很抱歉的壞顯示器,但我努力去理解如何輕鬆地做到這一點
你在Windows下運行嗎? – Jasper
嘗試替換\ r以及 – thumbmunkeys
是的,但與cygwin –