Re: [Dev-C++] Can't run a simple program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Carlo <car...@li...> - 2005-04-07 10:02:03
|
Ecpin ha scritto lo scorso 07/04/2005 11:16:
> Hi,
[...]
> 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 (argc > 1)
+ {
- if ((fp = fopen(argv[1], "r")) == NULL)
+ fp = fopen(argv[1], "r");
+ if (fp != NULL)
> {
- if ((stdprn = fopen("PRN", "w")) == NULL)
+ stdprn = fopen("PRN", "w");
+ if (stdprn != NULL)
+ {
> while(!feof(fp)) { // error occurs here,
> fgets(str, 79, fp); // or here
- fprintf(stdprn, "%s", &str);
+ fprintf(stdprn, "%s", str);
> }
+ fclose(stdprn);
+ }
+ fclose(fp);
> }
- fclose(fp);
- fclose(stdprn);
> return 0;
> }
Not sure that diff-like notation is clear (- means remove this line, +
means insert this), but this should work.
|