Heres the code I have so far
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
main()
{
int x=1;
int selection;
char username[10];
char buf[160];
char *p;
printf("Please Enter you Username \n");
scanf("%s", username);
printf("your username is %s \n", username);
while(x!=0)
{
printf("please choose an option from the following menu:\n\n");
printf("1. Send a message\n");
printf("2. Check userlist\n");
printf("3. Log off Program\n");
scanf("%d", &selection);
switch(selection)
{
case 1 : printf("whats the message?\n");
if (fgets(buf, sizeof(buf), stdin) !=NULL)
{
printf("the message is as follows : %s\n", buf);
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0';
printf ("And now it's >%s<\n", buf);
}
break;
case 2 : printf("the userlist is as follows \n");
break;
case 3 : printf("now logging you off \n");
x=0;
break;
}
}
}
The thing is the fgets wont allow me to enter anything. I have tried it without the if loop and with it but neither works.
any ideas?