matmatmat
October 23rd, 2009, 03:53 PM
I'm thinking of a program that gets passed a file of data, eg:
Name Score
Bob 2
Mat 3
Jane 7
then makes a table like this:
|------------|
|Name |Score |
|-----|------|
|Bob |2 |
|Mat |3 |
|Jane |7 |
|------------|
the number of fields may be more than two.
My idea was:
get 1st line
scanf("%s", string);
int a = spaces_count(string);
a++;
if (a == 2){
scanf("%s %s", num[0], num[1]);
}
Is there a better way?
Name Score
Bob 2
Mat 3
Jane 7
then makes a table like this:
|------------|
|Name |Score |
|-----|------|
|Bob |2 |
|Mat |3 |
|Jane |7 |
|------------|
the number of fields may be more than two.
My idea was:
get 1st line
scanf("%s", string);
int a = spaces_count(string);
a++;
if (a == 2){
scanf("%s %s", num[0], num[1]);
}
Is there a better way?