![]() |
|
fopen |
type568
Member #8,381
March 2007
![]() |
I have gotten a problem.. I want to save my texture in a text file. This way I can simple write a texture in notepad FILE* cfg=fopen("poly.cfg.txt","r"); if(cfg==NULL) return 1; And, the function returns 1. I have no idea why. I have tentheled (tripled you can say :p) check the name. It was originally poly.cfg.. I thought maybe it needs a *.txt file. The file is a text file, created and edited in notepad. I am using VS6. The *.exe file and my text file are in the same directory. Can anybody please tell me, why would "fopen("poly.cfg.txt","r");" return NULL? Thanks..
|
Inphernic
Member #1,111
March 2001
|
Second argument. -- |
GullRaDriel
Member #3,861
September 2003
![]() |
I second Inphernic , but I will give you the tip he mention: "Code is like shit - it only smells if it is not yours" |
gnolam
Member #2,030
March 2002
![]() |
... and now he'll never learn to look things up for himself. -- |
type568
Member #8,381
March 2007
![]() |
No.. This didn't help. cfg==NULL is true. And, by the way: in the borland 3.1 1992, which help I am using, uses "r". Edit: Can there be any other reason.. ?
|
Hard Rock
Member #1,547
September 2001
![]() |
Are you running from the IDE? Visual Studio runs exe's from a different path, so the text file shouldn't be in the path with the exe unless you are running it directly (eg double clicking on the exe as opposed to running from the IDE). I think it's one level up, but different projects can have different settings. Test running the exe directly and see if it helps. _________________________________________________ |
type568
Member #8,381
March 2007
![]() |
Thanks Hard Rick, I had a similar issue with a bitmap, so I tested this before asking for help here..
|
GullRaDriel
Member #3,861
September 2003
![]() |
Type568, you imo have two problem. The second was solved (path issue), but the first ... If you manage to write something in a file you fopen in readable only mode, well, have good time. "Code is like shit - it only smells if it is not yours" |
BAF
Member #2,981
December 2002
![]() |
You shouldn't be using "rw" unless you want to read AND write. "w" is what you likely want. |
type568
Member #8,381
March 2007
![]() |
I wanted to read only.. But generally, ANYTHING. I just want something except for NULL from my fopen().. Edit: Maybe somebody has some working code with fopen()? Just something working, with it's source. Here's mine: int init_kyb() { FILE* cfg=fopen("lol.txt","r"); if(cfg==NULL) return 1; } All the code, is attached... Thanks again.
|
Archon
Member #4,195
January 2004
![]() |
Quote:
I second Inphernic , but I will give you the tip he mention:
Quote: You shouldn't be using "rw" unless you want to read AND write. "w" is what you likely want. Is that a MSVC standard? I thought that it was r+ . |
James Stanley
Member #7,275
May 2006
![]() |
No, it's just r. EDIT: |
clovekx
Member #3,479
April 2003
![]() |
--- |
James Stanley
Member #7,275
May 2006
![]() |
or perror("fopen"); |
Ron Ofir
Member #2,357
May 2002
![]() |
How about creating a file and searching for it? That way you can know your path. And here's a better way to make sure you will load the file: char name[200]; get_executable_name(name, sizeof(name)); replace_filename(name, name, "poly.cfg", sizeof(name)); FILE * cfg = fopen(name,"r"); if(cfg == NULL) return 1; } There's also a way to change the execution path, but I don't remember how. EDIT: It is called the working directory can be changed using chdir. Please note that this is not ANSI C. |
Sirocco
Member #88
April 2000
![]() |
It probably doesn't matter given the compiler you're using, but a long time ago I got in the habit of specifying text or binary input and output, so I'd use "RB" or "RT" as the final argument, assuming you are reading and not writing. If writing open the file with "WB" or "WT". Oddly, with an older version of Borland C++ I've had issues with files not properly opening using read/write mode, so I never use that. --> |
Archon
Member #4,195
January 2004
![]() |
Quote: No, it's just r. I know that that works, but it looks like "rw" is supposed to mean read and write. |
type568
Member #8,381
March 2007
![]() |
Thanks a lot, to everybody.. I managed to read the file, and do some nice crap to what I've read. Here it is, VS6 workspace, Also the file with an *.exe included :p Edit: comments are greatly appreciated :p Edit(1): Gnolam, you are totally not right.
|
|