Tuesday, 11 December 2012

Return of C Test

Yep, folks, we've got another test this week on the C programming language. This time it's on arrays and strings (and pointers!!) so it's probably quite tricky. Wish me luck!

Oooo, a little test. Why won't this code compile properly?

#include <stdio.h>
char line[100];/* line of input data */
int  height;   /* the height of the triangle
int  width;    /* the width of the triangle */
int  area;     /* area of the triangle (computed) */

int main()
{
    printf("Enter width height? ");

    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d %d", &width, &height);

    area = (width * height) / 2;
    printf("The area is %d\n", area);
    return (0);
}

No comments:

Post a Comment