www.digitalmars.com         C & C++   DMDScript  

c++.dos.16-bits - fopen requires const char instead of char in other compilers

reply "Lars Hansen" <lars.o.hansen gmx.de> writes:
The following code produces an error about an explicit cast needed for arg 1
of fopen from char to const char. DMC version 8.29n
How do I get this code to work?
Miracle C compiles without warning or errors.


#include <stdio.h>

int main (int argc, char* argv[])
    {
     FILE f;

     f=fopen(argv[1],"r");

     fclose(f);

     return 0;
    }
Feb 16 2003
next sibling parent "Walter" <walter digitalmars.com> writes:
Replace:
    FILE f;
with:
    FILE *f;



"Lars Hansen" <lars.o.hansen gmx.de> wrote in message
news:b2nvhd$1bf7$1 digitaldaemon.com...
 The following code produces an error about an explicit cast needed for arg
1
 of fopen from char to const char. DMC version 8.29n
 How do I get this code to work?
 Miracle C compiles without warning or errors.


 #include <stdio.h>

 int main (int argc, char* argv[])
     {
      FILE f;

      f=fopen(argv[1],"r");

      fclose(f);

      return 0;
     }
Feb 16 2003
prev sibling next sibling parent reply "Lars Hansen" <lars.o.hansen gmx.de> writes:
of course ...


(actually I did that correctly in my original file, but the char conversion
error occured at  int main(int argc, char* argv[]){ int i; char b[4096]; ...
if(b[i]!=argv[1]) ...
                ^
I seem not to have watched the compiler output concentratedly enough)


thanks!


"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:b2orci$23m4$3 digitaldaemon.com...
 Replace:
     FILE f;
 with:
     FILE *f;
Feb 16 2003
parent Heinz Saathoff <hsaat bre.ipnet.de> writes:
Lars Hansen schrieb...
  int main(int argc, char* argv[]){ int i; char b[4096]; ...
 if(b[i]!=argv[1]) ...
^^^^ ^^^^^^^ | +----- type char* +----------- type char You try to compare a char with a char* which is type incompatible. BTW, be carefull when comparing pointers. In the above case a string compare would be better: if(strcmp(a, argv[1])==0) ...
 I seem not to have watched the compiler output concentratedly enough)
Compiler messages are somtimes confusing :-) - Heinz
Feb 16 2003
prev sibling parent "Lars Hansen" <lars.o.hansen gmx.de> writes:
Thank you very much!

that cleared a problem I had for me!

(tj, sometimes (when not using it for a long time) it's directly in front of
you and you don't recognize it (I didn't get the code to work as expected
actually): I need to dereference argv[1]! of course...)

Lars


"Heinz Saathoff" <hsaat bre.ipnet.de> schrieb im Newsbeitrag
news:MPG.18bab22821d8c3d69896b5 news.digitalmars.com...
 Lars Hansen schrieb...
  int main(int argc, char* argv[]){ int i; char b[4096]; ...
 if(b[i]!=argv[1]) ...
^^^^ ^^^^^^^ | +----- type char* +----------- type char You try to compare a char with a char* which is type incompatible. BTW, be carefull when comparing pointers. In the above case a string compare would be better: if(strcmp(a, argv[1])==0) ...
 I seem not to have watched the compiler output concentratedly enough)
Compiler messages are somtimes confusing :-) - Heinz
Feb 17 2003