I'm having problems reading or writing files in my C++ program.
I'm using Fedora 16 on a USB stick and Eclipse for C/C++ developers.

Here's snippet of code from my program. fp is always 0.
I've also got other code that is loading files (which always fail).

I've tried running Eclipse using 'sudo' but that doesn't help.
I don't receive any error messages.

FILE* fp = fopen("test.xyz", "r");
if(fp)
{
    fprintf(fp, "test123");
    fclose(fp);
}

Any help would be great. Thanks!

Chris

Recommended Answers

All 4 Replies

Sorry that should be "w" as the type parameter on the fopen call.

I assume you installed the CDT plugin for Eclipse? What is your OS, and what compiler are you using? Have you verified that your project is using the correct compiler, etc? Eclipse is picking about that sort of stuff.

Also, for me, on Linux/Unix systems at least, I MUCH prefer a simple Makefile and the standard C compiler options. If you are using Visual Stupido on Windoze, then you should really use the VS environment.

I'm using Fedora and setup a new project. Everything else was fine in the project.
The thing I figured out I was doing wrong was specifying the wrong type of slashes in the filenames.

I was doing:
folder\\filename.png
which works on Windows but not Linux.

But I should have been doing:
folder/filename.png
Which works on Linux.

Time for some abstraction of my file loading...

Thanks anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.