Why is this exception thrown in the visual studio C compiler?
Posted
by Shane Larson
on Stack Overflow
See other posts from Stack Overflow
or by Shane Larson
Published on 2010-03-21T04:16:31Z
Indexed on
2010/03/21
4:21 UTC
Read the original article
Hit count: 315
Hello. I am trying to get more adept and my C programming and I was attempting to test out displaying a character from the input stream while inside of the loop that is getting the character. I am using the getchar() method.
I am getting an exception thrown at the time that the printf statement in my code is present. (If I comment out the printf line in this function, the exception is not thrown).
Exception: Unhandled exception at 0x611c91ad (msvcr90d.dll) in firstOS.exe: 0xC0000005: Access violation reading location 0x00002573.
Here is the code... Any thoughts? Thank you.
PS. I am using the stdio.h library.
/*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);
}
}
© Stack Overflow or respective owner