/* A MUCH better way to get input from the keyboard * * from S. Oualline's book, "Practical C Programming, 3rd. ed." * * This method is not as finicky as scanf(), because fgets gets * one full line at a time * * BJ Furman 01OCT2010 */ #include int main(void) { /* Declare variables that you want to read in */ /* Your list of variables will probably be different! */ char char1; int var1; float var2; char string1[20]; /* an array to hold 19 characters */ /* Set up an array of characters to hold the user input */ char line[100]; /* put a user prompt here */ printf("Enter a string, a character, a float, and an integer separated by spaces\n"); /* get and process the user input */ fgets(line, sizeof(line), stdin); sscanf(line, "%s %c %f %d", string1, &char1, &var2, &var1); /* print out what you got */ printf("string: %s\tchar: %c\t\tfloat: %g\tint: %d \n", string1, char1, var2, var1); return 0; }