我想获得更多的熟练和我的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