0

I need to read data from a flat file [find below] into a linked list. Each line is a record and each record needs to be read into a different node. After I open the file using fopen(), I have the following problem:

1) How do I move from the first line of the file to the second when Im reading the data in the file?

The flat file is organized in the following manner:

username, password, access
username2, password2, access2
username3, password3, access3
...
...
...

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by gerard4143
0

So what your saying is the fields are comma separated and the records are newline separated?

yup.

0

This is a very simple version of how it might work

#include <stdio.h>
#include <stdlib.h>

char ch[100];

int main(int argc, char**argv)
{
	FILE *fd;
	if (!(fd = fopen("testfile", "r")))
	{
		fputs("could not open testfile!\n", stderr);
		exit(EXIT_FAILURE);
	}

	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);

	fclose(fd);

	exit(EXIT_FAILURE);
}

the data file

this,is,line,one
this,is,line,two
this,is,line,three
this,is,line,four

Edited by gerard4143: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.