我想獲得更多的熟練和我的C編程,我試圖測試顯示輸入流中的字符,而在獲取該字符的循環內。我正在使用getchar
方法。爲什麼在Visual Studio C編譯器中引發此異常?
我在我的代碼中存在printf
語句時出現異常。 (如果我在此函數中註釋掉printf
行,則不會拋出異常)。
例外:0000005:訪問 衝突讀取位置0x00002573在 firstOS.exe 0x611c91ad(msvcr90d.dll)未處理的異常。
這是代碼...任何想法?謝謝。
PS。我正在使用stdio.h
庫。
/*getCommandPromptNew - obtains a string command prompt.*/
void getCommandPromptNew(char s[], int lim){
int i, c;
for(i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i){
s[i] = c;
printf('%s', c);
}
}
謝謝!很棒。 – 2010-03-21 04:27:12