Hi,

I realise this may be a simple problem but i've really been pulling my hair out at the moment.

I've got a text file, which I need to read each of the 15 characters (numbers and letters) on each line in to a new record in an array (called defarray) - but I can't seem to do it. I've managed to work out the code to read the text file and output each line but not save it into an array.

Text file (fp called = 'definitions') looks like;
ABCDEF123AAABB
ABCEEF123AADFB
ABCDDF123ADSHB
etc...

currently I have the following;

while(!=feof(definitions))
{
fscanf(definitions, "%s\n, & defarray[i]);
printf("s\n", &defarray[i]);
i++
}

I would appreciate an help or ideas with this. The script is a C script not C++ etc.

Thank you.

Check out this link. This will show you a better method to read an array.
http://irc.essex.ac.uk/www.iota-six.co.uk/c/i2_feof_fgets_fread.asp

Define a 2D array of chars (or 1D array of char pointers)
As you read a line of the file store it in a row of this 2D array

So at the end of the loop you will have a 2D array in which each row contains one line of the input file

1) Actually look at the information about CODE tags, don't just guess.
2) Is while(!=feof(definitions)) a valid while statement?
3) Don't use feof() to control a loop. Here's why

Hi, thank you all for your notes.

I've looked at the sites you've offered but dont seem to be able to make anything with them which suit my requirements.

I may not have explained the problem that well, or perhaps C can't do whats needed as i've extensively looked across the net and not managed to find a function which does what i need.

I've been attempting to read in each line of a text file as a new record in a multidimensional array making a sort of 'string' array. So I can do the same with another file and then compare each line of file 1 to all the lines in file 2.

e.g

file 1 file 2
AAA DDD
BBB EEE
CCC AAA

So the program would detect file 2 contains 'AAA' and report it back to the user.

Any ideas?
Thank you for your time

Hi, thank you all for your notes.

I've looked at the sites you've offered but dont seem to be able to make anything with them which suit my requirements.

They don't? What did the link tell you about feof() ?

You also never answered Q#2.

I may not have explained the problem that well, or perhaps C can't do whats needed as i've extensively looked across the net and not managed to find a function which does what i need.

Of course C can do what's needed. It's trivial. It's the programmer that needs to tell C to do it.

If you want help, you need to give proper information, not restate the obvious.
If you are having a problem, focus on the problem, not the end result.

What is the problem? Explain in detail. What happens that's wrong? What did you want to happen instead? Without that, we have no idea what you really need help with.

commented: "diff" must have been written in Pascal then ;) +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.