Just getting back into c (I've been dosing assembly for the last few months), so don't laugh at me :S I'm trying to read an input file. The fist line contains how many lines to read. The rest of the lines contain 3 words. Here's an example:
3
Hello, World and
Hello, DaniWeb and
Hello, anything else
I want to read the first line, and loop it that many times. This works. Then I want to read the next line, load the words into seperate variables and print them.
Here's my code:
#include <stdio.h>
FILE *infile;
char word1[256];
char word2[256];
char word3[256];
int firstline();
void nextline();
int quit();
int main() {
int max;
int count = 0;
infile = fopen("input.txt", "r");
max = firstline();
while(count != max) {
printf("%s %s %s", word1, word2, word3);
count++; }
return quit(); }
int firstline() {
int num;
fscanf(infile, "%d", &num);
return num; }
int quit() {
fclose(infile);
getchar();
return 0; }
void nextline() {
fscanf(infile, "%s %s %s", word1, word2, word3); }
Any ideas?