I think I found what you were talking about here - http://cboard.cprogramming.com/c-programming/151288-scanning-new-line.html - I remember it now; how can I forget this classic by soma
Nominal...
Type: Posts; User: Click_here
I think I found what you were talking about here - http://cboard.cprogramming.com/c-programming/151288-scanning-new-line.html - I remember it now; how can I forget this classic by soma
Nominal...
Here is one that the whole family can enjoy...
char *get_user_input (const char *prompt, char *input_string, size_t input_string_size);
int main(void)
{
char *fname;
Initialising is always a good idea.
strchr is a better idea
const char * is a better idea
I don't know where you are seeing Nominal Animal's suggestion, though...
The extra blank lines...
There is one last thing to worry about - That's the return value from fgets -> If this is NULL, there is a big problem. I've implemented this with a return value. It would also be worth mentioning...
If you wanted my advice on how to implement this into your code, turn this into a function like this:
void get_user_input (char *prompt, char *input_string, size_t input_string_size);
int...
I think that you can see that it keeps pulling stuff off stdin until either a new line is found, or the EOF.
"continue" is used in loops to say "start the loop again". It is not needed: However,...
Have a look at this example:
int main(void)
{
char *fname;
int read_ok;
fname = malloc(MAXNAME * sizeof(*fname));
No, it said
You have a choice -
char *storage; // Create a storage container to store the answer from the user in fgets.
storage=malloc(sizeof(MAXNAME)); // Allocate memory for the pointer just created...
char *storage; // Create a storage container to store the answer from the user in fgets.
//Should be
company *storage; // Create a storage container to store the answer from the user in fgets.
char *storage; // Create a storage container to store the answer from the user in fgets.
storage=malloc(sizeof(company)); // Allocate memory for the pointer just created with malloc
...
...
Just update the declaration to MAXNAME + 1, not the value of MAXNAME
Give your string an extra character and initialise this last character to '\0'
The '\0' character is not being put at the end of the string.