Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Every time you visit for the FIRST TIME today... [Part 1]

Name: Anonymous 2013-10-20 22:56

Post a random function that you made. May be from any project you've done or make one impromptu.

Any QUALITY is allowed. No bullying!

Name: VIPPER 2013-12-26 18:48

>>152
while((c = fgetc(f)) != EOF)
in a system where char is unsigned and sizeof (char) == sizeof (int) EOF is a vaild character
better use while((c = fgetc (f)) != EOF || (!feof (f) && !ferror (f))

exit (1);
you cause a implemented defined behavior by returning 1, the standard values are 0, EXIT_SUCCESS, EXIT_FAILURE

fprintf(stderr, "\n");
since \n is a single character I would use fputc ('\n', stderr); but this is not really a problem

void *
you don't return something from that function, you should retrun void and in C11 you can add _Noreturn with the void

(f = fopen(*++argv, "r")) || error("fopen", "Couldn't open %s", *argv);
what if *++argv == NULL? undefined behavior. you must check it. I would use if (argv[0] && argv[1]) (f = fopen (argv[1], "r")) || error ("fopen", "Couldn't open %s", argv[1]);

In my opinion using a error function that destroys the progam is bad for two reasons:
1) the program must start from main and end in main and each function should have one return, using exit() makes my cry ;-;
2) in most cases closing the program on a error is a bad idea, it can create data loss. The worst is what it's used in libraries

other problems:
you don't check the return value of fprintf, vfprintf, putchar and you don't do anything if fgetc (f) == EOF && ferror (f), you don't use GNU Style

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List