We are will use vi to create ai file with a C program. Start by typing:
vi put.c
When you have finished editing your program, you can compile it by writing
gcc put.c
If the program compiles without errors, you're ready to submit it. As usual, submit hardcopy or on Moodle.
The program is below:
/* Clearing stdin of extra characters. */ #include <stdio.h> void clear_kb(void); int main(void) { int age; char name[20]; /* Prompt for user's age */ puts("Enter your age."); scanf("%d", &age); /* Clear stdin of any extra characters */ clear_kb(); /* Now prompt for user's name */ puts("Enter your first name."); scanf("%s", name); /* Display data */ printf("Your age is %d.\n", age); printf("Your name is %s.\n", name); } void clear_kb(void) /* Clear stdin of any waiting characters */ { char junk[80]; fgets(junk, 79, stdin); }