Re: [Dev-C++] Can't run a simple program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Josh M. <mrl...@gm...> - 2005-04-07 11:10:22
|
You're having the if statements run if there's a problem opening
either file, which is your problem. You should be checking if fopen()
returns non-NULL.
Josh
On Apr 7, 2005 7:16 PM, Ecpin <ec...@ne...> wrote:
> Hi,
>
> After many years I returned to C and used Bloodshed Dev-C++ IDE v4 to
> code a simple routine (as MS-DOS/console application) that should print
> a text file.
>
> But, even though the code looks correct and compiles succesfully, when I
> run the program, windows displays the following error msg and the
> program terminates.
>
> **- error msg:
>
> PrintMe.exe - Application Error
>
> The instruction at "0x78024222" referenced memory at "0x0000000c".
> The memory could not be "read".
>
> Click on OK to terminate the program
> Click on CANCEL to debug the program
>
> <OK BUTTON> <CANCEL BUTTON>
>
> **- end of error msg
>
> The code I wrote is reproduced below:-
>
> **- code begins:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
> char str[80];
> FILE *fp, *stdprn;
>
> if ((fp = fopen(argv[1], "r")) == NULL)
> {
> if ((stdprn = fopen("PRN", "w")) == NULL)
> while(!feof(fp)) { // error occurs here,
> fgets(str, 79, fp); // or here
> fprintf(stdprn, "%s", &str);
> }
> }
> fclose(fp);
> fclose(stdprn);
> return 0;
> }
>
> **- code ends
>
> Pls advice what could be wrong
>
> Rgds
> R3
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|