CSC 275 - Operating Systems Practicum

Dr. R. M. Siegfried

Assignment #5 - Using vi to create a C program

Due Friday, September 30, 2022 (Section 1)

Due Monday, September 28, 2022 (Section 2)

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);
}

[Back to the Assignment List]