Hi everyone I am writing a program where the input data is to be formatted into a table...
The input looks like this:
Code:
Header Header Header Header Header
2081 12 2007 4 795500
2180 07 2009 6 165000
2140 12 2008 5 689000
2153 03 2008 4 491500
2140 02 2010 5 886500
2005 11 2007 4 776500
2151 07 2007 5 305500
2199 12 2010 5 895000
2101 04 2010 7 389500
2176 02 2008 2 959500
So this input data is to be formatted into a table..
The code i have for my program is this:
Code:
#include <stdio.h>
int main (int argc, char *argv[])
{
int array[10][5];
int i=0;
int j=0;
for (i=0;i<10;i++) {
for (j=0; j<5;j++) {
scanf("%d", &array[i][j]);
}
}
printf("\n|");
for (i=0;i<10;i++) {
for (j=0; j<5;j++) {
printf(" %4d ", array[i][j]);
printf(" ");
}
printf("|\n|");
}
return 0;
}
This code works perfectly IF the headers weren't there.....Because they are characters my resulting table is a mess!!!!!
I need a way for scanf to ignore the characters....I looked around on the net and saw that i have to use some thing like
Code:
char c = ' '; //give c an initial value
//consume characters from the input until we get to the end of the line
while(c != '\n') {
scanf("%c", &c);
}
BUT i do not know where to place this in the code or how it removes the characters...
Any help is appreciated...