I was writing a chat server program as part of my network lab when I observed a very strange behavior:
printf("Recieved login info.\n"); //works
printf("Username: %s\n", ui->username); //works
printf("Passward: %s\n", ui->password); //works
//TO_AUTHENTICATE, if failure, send appropriate reply
printf("makeitwork"); //does not work
while(ui != NULL)
{
printf("here2");//does not work
if(strcmp(ui->username, record.username) == 0 && strcmp(ui->password, record.password) == 0)
{
strcpy(userRecords[sockfd].username, record.username);
userRecords[sockfd].status = ONLINE;
printf("Successfully authenticated %s.\n", userRecords[sockfd].username);
// sendOnlineUsers(sockfd, registeredUsers);
return SUCCESS;
}
ui = ui->next;
}
In the above code segment, the first, second and third printf statements works, but from the 4th onwards, it does not work.
But if I comment out the if
statement printf("here2");
, everything works normally.
I used gdb to execute the program line by line:
(gdb)
Recieved login info.
94 printf("Username: %s\n", ui->username);
(gdb)
Username: user-1
95 printf("Passward: %s\n", ui->password);
(gdb)
Passward: pass
98 printf("makeitwork");
(gdb)
99 while(ui != NULL)
(gdb)
101 printf("here2");
(gdb)
102 if(strcmp(ui->username, record.username) == 0i)//&& strcmp(ui->password, record.password) == 0)
The printf is executing, but there is no output on the terminal.
What is happening?