I copied this out of the FAQ - not to criticise, but to ask a question, and since it is easier to cut and paste...
Code:
int main()
{
char buf[BUFSIZ];
char *p;
printf ("Please enter a line of text, max %d characters\n", sizeof(buf));
if (fgets(buf, sizeof(buf), stdin) != NULL)
{
printf ("Thank you, you entered >%s<\n", buf);
/*
* Now test for, and remove that newline character
*/
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0';
printf ("And now it's >%s<\n", buf);
}
return 0;
}
The part I am wondering about is this:
looks like a declaration of a char pointer 'p'. Its not pointing to anything, is it? Then p is used later without ever making it point to anything? If someone would explain how this works, I would appreciate it. Its the last part of this code that I don't quite get.