【发布时间】:2010-03-21 04:16:31
【问题描述】:
我正在努力提高我的 C 编程能力,并尝试在获取字符的循环内部测试从输入流中显示一个字符。我正在使用getchar 方法。
当我的代码中出现 printf 语句时,我收到了一个异常。 (如果我注释掉该函数中的printf 行,则不会抛出异常)。
异常:未处理的异常 0x611c91ad (msvcr90d.dll) 在 firstOS.exe: 0xC0000005: 访问 违规读取位置0x00002573。
这是代码...有什么想法吗?谢谢。
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);
}
}
【问题讨论】:
标签: c visual-studio exception printf getchar