Question #44554

How is it possible to create a table header that is filled in with a standard input from a text file using arrays?
1

Expert's answer

2014-07-31T09:25:50-0400

Answer on Question #44554, Programming, C

Problem.

How is it possible to create a table header that is filled in with a standard input from a text file using arrays?

Solution.

Code


#include <stdio.h>
int main()
{
    char headers[20][40]; // array to store headers
    int n = 0; // number of elements in headers
    int i; // counter
    // Read data
    FILE *file = fopen("headers.txt", "r");
    while(fscanf(file, "%s", headers[n]) != EOF)
    {
        n++;
    }
    fclose(file);
    // Output results
    for (i = 0; i < 13 * n + 1; i++) // top border
    {
        printf ("-");
    }
    printf("\n!");
    for (i = 0; i < n; i++) // headers
    {
        printf ("% - 10s |", headers[i]);
    }
    printf("\n");
    for (i = 0; i < 13 * n + 1; i++) // bottom border
    {
        printf ("-");
    }
    return 0;
}


Result



http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS