Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » i can't use "fopen" function in my program

Credits go to Evert, marcin, and ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
i can't use "fopen" function in my program
marcin
Member #5,814
May 2005

Quote:

... doesn't complete path elements (or makes it bad)

If you have it try use it. Some XPs (new or with updates) has it but it works terrible.

gillius
Member #119
April 2000

Tab completion for Windows XP works for me (but it doesn't work identical to Linux! It is different but it works as designed). It also exists in Win2000, with a registry "hack"

Gillius
Gillius's Programming -- https://gillius.org/

marcin
Member #5,814
May 2005

Quote:

Tab completion for Windows XP works for me ...

OK, I have habits from Linux.
If it doesn't complete name of a file or a dir after I press TAB it doesn't work for me. :)

EDIT:

(Habits are the second nature of Human.)

Quote:

but it works as designed

Everything works as designed... ;D
(Only often designers can't predict some additional features...)

sofi saltana
Member #5,962
June 2005

the files i have in my folder are:
-agenda.c
-agenda.dev
-agenda.exe.Manifest
-agenda.exe
-agenda.layout
-agenda.o
-agenda_private.h
-agenda_private.rc
-agenda_private.res
-makefile.win
-teraes.txt
-6 bitmaps(they are just bitmaps used as buttons)

(note that this folder contains all the files that were generated from other compilations)

HoHo
Member #4,534
April 2004
avatar

-teraes.txt vs if ((fichero=fopen("tareas.txt","r+t")) ==NULL)
Is that a typo?
Does this program work if you execute the program directly(doubleclick on
it in explorer)?

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

marcin
Member #5,814
May 2005

Quote:

Is that a typo?

Good work Sherlock HoHolmes !!! :)

(But I said at start that he has not tareas.txt) ;D

sofi saltana
Member #5,962
June 2005

Marcin >(But I said at start that he has not tareas.txt)

i do have tareas.txt in the same folder i have my executable. but i still can't get this file opened. Please try to help.

marcin
Member #5,814
May 2005

Quote:

Please try to help.

Did you run executable from command line window and with printf(...) in code?

EDIT:

Can you compile this example:

1#include <stdio.h>
2#include <stdlib.h>
3 
4 
5int main(void)
6{
7 FILE *fichero;
8 
9 if ((fichero=fopen("tareas.txt","r+t")) ==NULL)
10 {
11 
12 printf("\nError al abrir fichero.\n");
13 exit(EXIT_SUCCESS);
14 }
15
16 fprintf(fichero, "%s", "asdf");
17 fclose(fichero);
18 
19 return 0;
20}

And run it.

sofi saltana
Member #5,962
June 2005

yes i did but my program never execute the code lines that suppose to open file and report if the file is opened. And as you said i tried with allegro_message and printf but i get the same result

marcin
Member #5,814
May 2005

And what about the code from my previous post (the EDIT section)?

Quote:

... my program never execute the code lines that suppose to open file and report if the file is opened.

But if it's not opened you should obtain message.

EDIT:

I just have compiled you code.

I run it and the file is opened OK.

But there is another problem. GUI is opened and closed immediately.

And this appear after:

do_dialog(the_dialog, -1);

sofi saltana
Member #5,962
June 2005

i compiled it and it gives no problem (it worxed). I already tried this earlier.
When i saw that it worked i wondered if the problem was in the allegro way to execute porgram, or something with allegro anyway; thats why in the code i attached in my first question the fopen was put before allegro_init.
even then it didn't worked so i got run out of ideas.

EDIT:

i cant get it working in my computer y would like to get the code of the open file to ensure how is the code that works(because i changed my code many times, maybe it will work even in my computer).
About the dialog it is supposed to open the dialog the_dialog and when this dialog opens, the user have to choose if he wants to add a new task. If he choose to add, the aniadir function will change a variable that will make switch enter the dialog aniadirtarea. But "the_dialog" dialog should not close automatically.

marcin
Member #5,814
May 2005

Can you replace your code with this:

if ((fichero=fopen("tareas.txt","r+t")) ==NULL){

 printf("\nError al abrir fichero.\n");

}

else

printf("\nfichero ABIERTO.\n");

And run it from command line.

Read EDIT in my previous post about problem with the GUI.

EDIT:

I have question:

In Allegro 4.0.3

allegro_message()

works without set_gfx_mode() ?

EDIT:

(If do you use 4.0.3 version of course)

Evert
Member #794
November 2000
avatar

Quote:

In Allegro 4.0.3

allegro_message()

works without set_gfx_mode() ?

Yes. Actually, you should only use it if you're not in graphics mode.

sofi saltana
Member #5,962
June 2005

ok! you really gave me the key to the problem i have. The problem is a big fault i made at creating the txt file. Unconsciously i created a tareas.txt.txt file, thats why i couldn't get my file opened, because i never called it.
As Marcin said, and Evert confirmed (thank you both for the help), allegro_message don't work in graphics mode. That's why i had the impression that those line of code never got run.
When Marcin told me that my code worked i had the confirmation that there was something wrong with me.

i'm really glade to have found these place. thank you all of you speccially MARCIN & REYBRUJO both of them helped me trough lots of messages.

marcin
Member #5,814
May 2005

Quote:

As Marcin said, and Evert confirmed (thank you both for the help), allegro_message don't work in graphics mode.

I'm only asked that it works without graphics mode.
(I'm newbie in Allegro)
(But path was good)

Evert said that we shouldn't use it in gfx mode.

:)

 1   2 


Go to: