Noone has posted revised code for fopen.
Noone has posted revised code for fopen.
You should read all the posts thoroughly, in particular the one by Unregistere21.Originally posted by drdroid
Noone has posted revised code for fopen.
You must do better error handling, there's no point in continuing the program if the file open fails.Code:if ((filein = fopen("World.txt", "rt")) == NULL) { MessageBox(NULL, TEXT("Failure"), TEXT("Test:"), 0); }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
that checks to see if the variable opens the file. That is not a fix that is a check. I already used that.
OK, look at evidence so far:
I said:
>>Use this snippet: sprintf(buffer, "%p %p", string, f); in the readstr() function to trap the values of the two key pointers.
You responded with:
>>The buffer messagebox comes up as 0066FA6C 00000000
Therefore, the value of f is NULL. f is a FILE*, which is populated by this:
>filein = fopen("World.txt", "rt")
Therefore, we can assume that the fopen() is returning NULL, meaning that the file open failed, and the filein variable is not usable.
So now you say:
>>that checks to see if the variable opens the file. That is not a fix that is a check. I already used that.
Huh? What I suggested wasn't supposed to fix the open, only highlight the problem and stop you from using a FILE* that is broken.
Does this message box pop up:
Code:if ((filein = fopen("World.txt", "rt")) == NULL) { MessageBox(NULL, TEXT("Failure"), TEXT("Test:"), 0); }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Hurray, we're finally getting somewhere.Originally posted by drdroid
yes that message pops up.
Are you sure :
1 - World.txt exists.
2 - it's in the correct directory (ie the programs working directory).
3 - you have read permission to it
#2 is the most likely cause of the problem, imho.
Anyway, I can't help you any further, we've found your problem. Once you find out why you cannot access World.txt, and fix that, you'll be away again.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I couldn't believe it, I thought I had tested the file in both spots. Well, something so obvious; again, typical of me. Thank you so much.