Pointer question: *ptr with gets()
Hi everyone:
I wonder why when i use gets() function in statement generates an error, but when used with a pointer: *ptr it works fine:
" if (gets(input) != NULL) " -----generate an error
" if (*(ptr=gets(input) !=NULL)" -----works fine
what exactly does the pointer do here exactly??
Hopfully all those experienced programmers can answer this question....
ty.
Re: Pointer question: *ptr with gets()
Quote:
Originally posted by muk_luk
Hi everyone:
I wonder why when i use gets() function in statement generates an error, but when used with a pointer: *ptr it works fine:
ty.
as i see , no one gave u the answer till now,
the answer for ur question is the following,
u should first determine the function prototype for gets
here it is
char *gets(char *s)
that means that this function reads character string and puts this string in a string s {pointer]
that is why u should use it with pointer
Re: Re: Pointer question: *ptr with gets()
Quote:
Originally posted by system_eyes
as i see , no one gave u the answer till now,
No, that has nothing to do with why he didn't get an answer. He didn't get an answer he liked because he failed to provide enough code. What is 'input' in his code? Can you be sure? No, you can't. He never says what 'input' is.
Furthermore, the provided code that he says works wouldn't even compile, because he doesn't have enough ) marks.
And finally, he never says what error he gets. Simply stated, he says "generates an error". Well that's all fine and dandy, but it does absolutely nothing for us when we're trying to tell him what he's doing wrong.
In short, if he had avoided gets all together, he wouldn't be having that problem. ;)
Quzah.