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.

Edited 6 Years Ago by WaltP: Fixed CODE tags. Good try, but you may want to actually read about them.

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.

Comments
"diff" must have been written in Pascal then ;)
This article has been dead for over six months. Start a new discussion instead.