Originally Posted by
whiteflags
It's not really something you need to implement... Even if you didn't read it with a scanf call like userxbw's, if the user knows how the program works, then they could just type ahead. The first scanf for the menu would read the i, and then the second scanf for the id would read the number.
I would be careful though, the best way to read letters in scanf is to start the string with a space and then the %c specifier. The space will stop any stray \n from being read into your menu option variable (the one that you switch on later).
so that is the trick. I'm going to go give that a try.
something like
Code:
#include <stdio.h>
int main (void)
{
char boo[10];
int a;
printf("enter id and name\n");
scanf(" %d", &a);
scanf(" %s", boo);
switch (a)
{
case 32:
printf("got id: %d name: %s\n",a,boo);
break;
default:
printf("didn't get anything\n");
break;
}
return 0;
}
results
Code:
userx@slackwhere:~/bin
$ ./testing_scanf
enter id and name
32 bob
got id: 32 name: bob
or this
Code:
#include <stdio.h>
void incert(int d)
{
printf("got id: %d ",d);
}
int main (void)
{
char boo[10];
int a;
printf("enter 32 \n");
scanf(" %d", &a);
switch (a)
{
case 32:
printf("enter id and name\n");
scanf(" %d", &a);
scanf(" %s", boo);
incert(a);
break;
default:
printf("didn't get anything\n");
break;
}
printf("name: %s\n",boo);
return 0;
}
results
Code:
userx@slackwhere:~/bin
$ ./testing_scanf
enter 32
32
enter id and name
55 bob
got id: 55 name: bob
of does it have to be a c and is that not just one char (letter)?