![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
i can't use "fopen" function in my program |
sofi saltana
Member #5,962
June 2005
|
i get problems when i try to use stdio.h "fopen" function in my program. i just try to save information of appointments in a txt file but as far as i am concered i can't get my file opened. I am in such a hurry and i need someone to help me desperately. I will attach my "C" file here so that anyone that wants to help can see the code i'm talking about. PS: Sorry if my english is not correct. I hope you understand. |
CGamesPlay
Member #2,559
July 2002
![]() |
if ((fichero=fopen("tareas.txt","r+t")) ==NULL)What is r+t? You want that to be "w+", I think. -- Ryan Patterson - <http://cgamesplay.com/> |
marcin
Member #5,814
May 2005
|
Code is good but you have not file "tareas.txt" on a disk. |
PaulSiramy
Member #2,748
September 2002
![]() |
If the file can't be opened, then your program tries to use allegro_message(), but allegro is not initialised yet, so I guess it crash. Move allegro_init(); to the top, and check again.
|
marcin
Member #5,814
May 2005
|
Of course allegro_init() ... |
sofi saltana
Member #5,962
June 2005
|
I have "tareas.txt" in the same folder where i have my project so there must be no problem, isn't it? correct me if i'm wrong. it could be the problem. I know that the allegro_message() is not in its place. At first i put it after allegro_init() but even then it didnt opened the file, nor executed none of the 2 allegro_message(). And that is the real problem i have THE PROGRAM DON'T EXECUTE THE "fopen" AND BOTH OF THE "allegro_message". |
HoHo
Member #4,534
April 2004
![]() |
Quote: I have "tareas.txt" in the same folder where i have my project so there must be no problem, isn't it? Where is the executeable and from where do you call it(from IDE, shortcut, ...)? __________ |
marcin
Member #5,814
May 2005
|
Put the executable and text file in the same directory. Replace allegro_message() with: printf("\ncan't open file\n"); And run your program from command line window. |
ReyBrujo
Moderator
January 2001
![]() |
Do you doubleclick the executable? -- |
sofi saltana
Member #5,962
June 2005
|
my executable is in a folder on my desktop but i don't understand what you wanna say with from where i call it from. i just compile my program with dev-c++. is that what you are asking for? |
ReyBrujo
Moderator
January 2001
![]() |
Do you execute it with F5 only? If so, check inside your project folder. There must be a Debug and a Release folder. Put the text file inside each of those folders (it is possible you only have Release or Debug). -- |
sofi saltana
Member #5,962
June 2005
|
i am not really sure of what you are saying. Would you tell me the extensión of the files you are talking about. I have a lot of files in my folder (".res","makefile.win",".layout",".exe.manifest",".rc", but some of them buy stay there from other compilations of my code). |
Rampage
Member #3,035
December 2002
![]() |
-R |
ReyBrujo
Moderator
January 2001
![]() |
You have your files in a folder, say, "C:\MyProject". When you compile with Dev-C++, it may create a folder and put the object and executable files there. So, it is possible Dev-C++ puts the executable file in "C:\MyProject\Debug". If you have your text file in "C:\MyProject", the executable won't read it. So, get absolutely sure the executable you are running is in the same directory as your text file. Windows is a bit strange and may search for your files anywhere. (Edited: Check this link for a proper way of finding the path to your resources). -- |
miran
Member #2,407
June 2002
|
When you compile a .c file, you get a .exe file. Put the .exe file in the same folder as the .txt file and run it from the command prompt! -- |
marcin
Member #5,814
May 2005
|
Quote: my executable is in a folder on my desktop Put into this folder file tareas.txt. Open this folder and if you have win98: - click start button command - in black window type name of your executable file if you have winXP - create empty text file with name "cmdline.cmd" cmd - save and close this file |
CGamesPlay
Member #2,559
July 2002
![]() |
marcin: Congratualations! Most redundant method of opening a program this week! Try just: if you have winXP - click start button cmd - in black window type name of your executable file -- Ryan Patterson - <http://cgamesplay.com/> |
marcin
Member #5,814
May 2005
|
Quote: marcin: Congratualations! Most redundant method of opening a program this week!
Thank you !!! But seriously I had windows XP and if I just type "command" in "run" window, I always landed on Desktop (or MyDocuments, I don't remember exactly) (even if I opened another folder before cmd). |
CGamesPlay
Member #2,559
July 2002
![]() |
Do you know what "cd" does? -- Ryan Patterson - <http://cgamesplay.com/> |
sofi saltana
Member #5,962
June 2005
|
i just tried your way to avoid problems with the location of the file, ReyBrujo, but i still have problems. when i try to compile it i get the "permission denied" error. |
marcin
Member #5,814
May 2005
|
Quote: Do you know what "cd" does?
I know but under windows TAB doesn't complete path elements (or makes it bad) (Linux has this tool). EDIT: Quote: ..when i try to compile it i get the "permission denied" error. Maybe you are running you program under debugger during compilation. |
miran
Member #2,407
June 2002
|
Press ctrl+alt+delete and in the window that pops up click the processes tab, find your exe and kill it. Then try compiling again. -- |
sofi saltana
Member #5,962
June 2005
|
>Maybe you are running you program under debugger during compilation i dont really understand what you want to say with this. i am using dev-c++ compiler and as far as i am concerned i can't compile the code while using debugger dev-c++ judt dont let you. But that dont seem to be my problem i have some lines of code that my program just dont run (see above: fopen() & allegro_message()), i even changed the allegro_message functions with printf functions but i still cant get them run. REYBRUJO When i compile my project the compiler don't create any Debug folder i just have everything mixed-up |
ReyBrujo
Moderator
January 2001
![]() |
What do you have in your directory? Post the names of the files. -- |
CGamesPlay
Member #2,559
July 2002
![]() |
I don't want to derail this thread, so this will be my last reply: marcin: Windows XP with cmd does have tab completion of path names. -- Ryan Patterson - <http://cgamesplay.com/> |
|
1
2
|