Writing to a file

Hello, ive been writing c and c++ for many years now, though it seems that im no expert in this field. Does anyone know if it is possible to read and write from files. I have succeeded before, but it does not work at all today.

FILE * pFile;
pFile = fopen ("myfile.txt","w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
printf("i open file\n");
}else
printf("i open file not\n");
return 0;


When i run this it says that i succeeded to open the file. I have also tried writing to tons of different files, names. Even tried to open files, but that is WAY beyond my abilities. The files ive been trying to write to does not exist, i have been searching my entire harddrive about 290 times now.

Is there anyone who has ever succeeded to save information in a file, that remembers how it works?
Hello, ive been writing c and c++

http://cplusplus.com/doc/tutorial/files/
Copied the example, still the same problem. It just wont complain or write anything.

Im writing in code::blocks if that has anything to do with it.
Seems like it is code::blocks that is not working correctly. It contains some sort of error. My programs are saving all my files in a top-secret directory on the harddrive C:\Program Files\CodeBlocks\MinGW\bin\. In this directory it is hiding all my hello.txt, whyisitstillnotworking.txt and kuksugarhelvete.txt ive tried saving and all the .exe files.

codeblocks has of some reason decided that windows is not allowed to search for files in this folder. I think i should change program from codeblocks that is developed for nasa- and bank-programmers to something that works.
closed account (S6k9GNh0)
top-secret directoory huh?

slutbit, that's idiocy for many reasons. The main one being that you're the only one that has this problem but you still believe that it's the fault of one of the most popular open-source and free IDE's around
Last edited on
Ah, I see. Thank you for enlighten me :)

What would you call a folder that is not displaying files you are searching for? Please tell me, because i have lots of trouble understanding things. My brain works a bit slower than most others, so please think about this when replying me.

I have used this software for quite a while but havent come across this error, i acctually only used VC++ and the gcc-, g++-compiler before in linux.
hello slutbit..y took a look at you're source code and it seams so work just fine..the option "w" creates a new .txt document and writes (fopen example) int it..now y hope you now that to be able to open/read/write on a specific file the cpp document and the exe must be saved in the same folder as the file you're opening/reading/writing.

y hope my advice helped you in some way.and keep up the good work :)

slutbit, something is certainly screwy here that is probably not a Code::Blocks or gcc (MinGW) error. Those programs are coded very well (owing to the massive would-be market for them), so we must assume that you made some mistake somewhere OR downloaded a version from an illegitimate source. Could you list your whole code and tell us where you got those Code::Blocks from?

-Albatross
Last edited on
y am using Dev-C++ for some time and y never had any problem with it.a simple interface,easy to use because you can find all the settings and what are you looking for easy.it is instaled in a folder on C/Dev-C++.and all the projects you make are in that folder..and y don't think that is bad or that you can't make serious programing with it. y searched some info about Code::Clocks and it seams very complicated to me..y am not saying that is not good,just too many stuff that probably y will never use.
if you want to take a look at it this is a link from where you can get the latest version.it dosen't take long to install so you have nothing to loose
http://www.softpedia.com/get/Programming/Coding-languages-Compilers/DEV-C.shtml
Topic archived. No new replies allowed.