I avoid strtok when dealing with empty fields.
A few reasons why, and an alternative:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
static const char filename[] = "file.csv"; /* the name of a file to open */
FILE *file = fopen(filename, "r"); /* try to open...
...and that it does not necessarily null terminate the destination string.
But as for "always use strncpy instead of...", I'd say, "No, avoid strncpy as well.
I generally go with #2, but only have the "public" functions in the header; any "private" functions are then static to the module.
What is an example of "all of the information contained within the function's header file"? Generally it should only be necessary data types and such: declarations...
NOOOOOOoooo!!! [The evil seed begins to grow.]
Use a buffer that ought to be "big enough". Use fgets to read input as a string. Examine the string to see if a newline is at the end. If so, there may be excess data. If not, possibly trim the newline. Or do other conversions, if necessary, using...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.