Problem with reading txt-files

Posted By: Roxas

Problem with reading txt-files - 12/31/10 12:25

Hey guys

I want to make a txt-file-based database as an item database for my project.

the database looks like this

Code:
1,Potion,8,0,0,0,4,0,0,2,0,0,0,2,40,
2,Remedy,8,0,0,0,4,0,0,2,0,0,0,2,60,
...



and so on.

The Problem is, that I'm not able to determine in which line the text cursor might be, and I'm also not able to place the cursor to a specific line. I tried a lot of things with file_seek, file_find and file_str_read but it doesn't work at all.

is there a way to specify the line in which the cursor in the txt file is or does anyone have a good solution for achieving this?

thanks in advance
Roxas
Posted By: Saturnus

Re: Problem with reading txt-files - 12/31/10 23:18

Just count the number of newline characters ('\n') until the current read/write position.

Something like this (pseudocode):
Code:
int number_of_lines = 1;
for (i = 0; i < file_position; i++) {
    if (file_chars[i] == '\n') {
        number_of_lines++;
    }
}


© 2024 lite-C Forums