July 26th, 2013, 02:00 PM
C project- main.c file question
I was writing a program that includes books as structures, and the user must type in the name/author of the book to find it. The typing is done with gets(), which needs <string.h>
The <string.h> and <stdio.h> and "file_name" are present in the implementation file, as it should be.
IN THE MAIN.C FILE it seems that <string.h> doesn't have to be included, because when i don't include it the program runs just the same; Even though i have a gets() command inside main !
However when i don't include the <stdio.h> the program doesn't work.
How come <string.h> is NOT necessary inside main but <stdio.h> is ?
I hope the question is clear enough :)
July 26th, 2013, 02:18 PM
1. you shouldn't be using gets() AT ALL. See gets is the tool of the devil
2. You don't need string.h because gets() is prototyped in stdio.h
Whoever told you to use gets() and look for it in string.h is plain wrong on two counts. You should ignore them from now on and find better quality sources of information.
July 26th, 2013, 02:31 PM
So what command should i be using for STRING INPUT ?
July 26th, 2013, 02:50 PM
Maybe you should actually read the link Salem posted. He posted it for a reason.
Originally Posted by C learner
July 26th, 2013, 03:57 PM
Use an accurate standard library reference source. Each function will be listed with its header file dependency. There are many such sources (including your compile's own documentation.
This one even comments on why it is deprecated and what you should use instead.
In other words, had you simply looked the function up, you would have found both that you were incorrect about the header and that the function in question is considered dangerous. Reading the manual is a far more efficient method of solving problems of this sort that posting to a forum.