Can somebody help me to find out why does my loop go forever, even when im telling it to stop once it finds NULL?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
struct user
{
int number;
char name[15];
struct user* next;
};
struct user* push( struct user* , char * , int fd);
int main()
{
char add2[20] = "MATT";
char add4[20] = "STEVE";
struct user * client;
struct user * node;
client = NULL;
client = push(client, add2, 5);
client = push(client, add4, 5);
for ( node = client; node != NULL; node = client->next)
{
printf("%s\n", node->name);
printf("%d\n", node->number);
}
return 0;
}
struct user* push( struct user* current_user, char * username , int number) {
struct user* newtop;
newtop = (struct user*)malloc(sizeof(*newtop));
strncpy(newtop->name, username, strlen(username) + 1);
newtop->number = number;
newtop->next = current_user;
return newtop;
}