I use gcc, so first, I compiled your code with debugging symbols (-g) and warnings turned all the way up (-Wall):
Code:
$ gcc -g -Wall -o planet planet.c
Wow, 374 lines of code and not a single warning! Awesome! That's probably the first time I've seen that happen here on a code sample longer than 20 or so lines. Congrats.
Now, I ran your code through a debugger (gdb):
Code:
$ gdb ./planet
GNU gdb (GDB) Fedora (7.1-34.fc13)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/charlesg/sandbox/test/planet...done.
(gdb) run
Starting program: /home/charlesg/sandbox/test/planet
Program received signal SIGSEGV, Segmentation fault.
__isoc99_fscanf (stream=0x0, format=0x8048f2b "%d") at isoc99_fscanf.c:31
31 _IO_acquire_lock_clear_flags2 (stream);
(gdb) backtrace
#0 __isoc99_fscanf (stream=0x0, format=0x8048f2b "%d") at isoc99_fscanf.c:31
#1 0x08048603 in main () at planet.c:89
Your file handle is NULL. You need to check for that before you go on trying to read from it. If you can't open your input or output files, you should probably bail out with an error. If we're going to help you, we need a sample input file. Also notice how a debugger helped me pinpoint the exact location of the seg fault. You should learn to use one, so you can find these things quickly and easily yourself.
Code:
if (strcmp(curr->lastName, last))
Your condition is backwards. Check the documentation for strcmp, you'll see it returns 0 when they match (which C treats as false). EDIT: Nevermind, you just have containsUser return true if the list doesn't contain the user, backwards, but it works. I'd fix that for readability sake.
Make sure your names are at most 20 chars including the null, or you will have a buffer overflow when you strcpy in addUser.
Code:
int addUser(struct UserWorkCompleted* head, char last[], char first[], int work, int type)
{
struct UserWorkCompleted* curr= head;
...
while (curr != NULL)
{
curr=curr->next;
}
...
curr=temp;
Note, curr is just a pointer. Your loop walks it off the end of your list, so curr is just pointing at NULL. Then, you make it point at temp, but that doesn't actually add temp to the end of the list. You need to stop curr at the last element (when curr->next is NULL), and then do curr->next = temp to link it up.