Hello Every one,

I am having trouble finding my correct condition to not run off the end of my file. So i am reading from a file and then tokenizing my data accordingly. My file has 16 lines and using my size function i get 18 lines instead since i have 2 blank lines at the end of the file. So, my code is reading this file tokenizing each line perfectly, my problem is that i can not stop at right place so if would not run off the end, i keep getting bus error and segmentation fault errors.. I am really confused. Thank you, Monte.

We have no way of knowing what is wrong if you don't show us the appropriate portion of your code. Without it, all we can do is make wild guesses.

What happens when you read a blank line and try to tokenize nothing?
How can you tell the blank line is read?
How is it different from the other lines?

when tokenizing blank lines it tokenizes like it does with other ones, so the output is blank. to figure out my mistake i have had my source file that had one line and two lines, three lines and so on.. so i could see this process once into a blank line it tokenized and showed blanks as its tokens. This how i could tell that its and tokenizes all lines including blank lines, however, i have not had way of telling it is the end of file and stop. i am not allowed to post my code or share it with any one due to academic dishonesty policy at my school, i apologize if i am asking wage question here, and appreciate your response. Monte.

Have you thought of just checking to see if the line is blank before tokenising it?

You tokenising routine needs to be robust enough that when it hits a problem it fails in a way you can catch and deal with (normally by just ignoring the line and possibly outputting an error).

That means not assuming anything, if you tokenise a line you expect to have 4 parameters separated by commas on then you don't assume the tokenisation worked. You check every pointer that gets returned to you before you use it for some other purpose.

Basically if something can go wrong you check it is going to before you do it. For everything.

Edited 6 Years Ago by Banfa: n/a

You should be checking for EOF during read. Look up your read function to see how EOF works.

I would make a more general function instead of telling it the exact number of lines.

Here's a page with an example of how to check for end of file.

...
i am not allowed to post my code or share it with any one due to academic dishonesty policy at my school,
...

I am a student also, and my school has an academic dishonesty policy as well. Obviously, I don't know the specific wording of your school's policy. Generally, however, there is no issue posting portions for discussion to request assistance. You are not "giving" the code to any of your classmates to cheat off from. If you're not comfortable posting your specific code, create an example program that demonstrates the issue. That will at least allow us to get an idea of what's going on.

"Academic Dishonesty" policies are intended to prevent plagiarism. The type of help that is offered here is also intended to prevent plagiarism. If you post portions of your code, the people here are supposed to make suggestions for you to consider and give examples. They are not supposed to simply take your code, edit it, and re-post it for you to copy paste. Even if you do copy/paste small snippets, simply cite your source with a comment in your code and you should be okay.

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.