this program hangs after taking first argument:-
#include <stdio.h>
#include <conio.h>
void ellip(char*,...);
int main(int argc,char* argv[]){
printf("a");
ellip("first argument",99,"second arg","thirdarg");
_getch();
return 0;
}
void ellip(char* m,...)
{ char com='c';
for(;;)
{
auto g=0;
while(com=='c')
{
printf("%d\nMatched Continue:-",g++);
scanf("%c",&com);
}
}
}
while the same program with a subtle modification(Addition of space)
scanf("%c ",&com);
Works Fine!
Is this some sort of bug in vc or a problem in my computer?
When the new line is read from
stdinand placed intocom, thencomis now'\n'and thefor(;;)loop will loop forever while thewhile(com=='c')will never be entered.scanf("%c ",&com);fixes the problem because the space character will causescanfto skip over all white space.See the MSDN article. FIrst bullet point explains what the space charcter is doing.