R
Rav
I have recently started working on GCC on red Hat 9. I have encountered
with some problems that i think should not occur (at least on Turbo C),
here they r:
Why does the following piece of code displays segmentation fault error:
{
int list[]={10,20,30,40,50};
int *p, *q;
p = list; //the problem is somewhere here, i checked with the
debugger
q = list+4;
}
another problem is that, while using fgets i am bound to use getchar to
remove the unread '\n'character in stdin as fflush(stdin) doesn't work.
char temp[20];
printf("\n Enter string: ");
getchar(); //fflush(stdin) was supposed to be used
fgets(temp,20,stdin);
it works fine this way but i think is not a proper approach. plz
suggest a solution. why isn't fflush(stdin) working, is there any
alternative of fflush(stdin).
plz help...thanks in advance
with some problems that i think should not occur (at least on Turbo C),
here they r:
Why does the following piece of code displays segmentation fault error:
{
int list[]={10,20,30,40,50};
int *p, *q;
p = list; //the problem is somewhere here, i checked with the
debugger
q = list+4;
}
another problem is that, while using fgets i am bound to use getchar to
remove the unread '\n'character in stdin as fflush(stdin) doesn't work.
char temp[20];
printf("\n Enter string: ");
getchar(); //fflush(stdin) was supposed to be used
fgets(temp,20,stdin);
it works fine this way but i think is not a proper approach. plz
suggest a solution. why isn't fflush(stdin) working, is there any
alternative of fflush(stdin).
plz help...thanks in advance