1752790 Members
6153 Online
108789 Solutions
New Discussion

HPUX11 fgets() warning

 
Marty Jorgenson
New Member

HPUX11 fgets() warning

Can some one shed some light on this problem for me.

While compling the following code on HPUX11 unix platform.

1 #include
2
3 void main()
4 {
5 FILE *infile;
6
7 static unsigned char buf[1024];
8
9 infile = fopen("test.txt", "r");
10
11 while (fgets(buf,80,infile) != NULL);
12 {
13 fputs(buf, stdout);
14 }
15 }

I get the following erros:

cc: "temp.c", line 11: warning 604: Pointers are not
assignment-compatible.
cc: "temp.c", line 11: warning 563: Argument #1 is not the correct type.
cc: "temp.c", line 13: warning 604: Pointers are not
assignment-compatible.
cc: "temp.c", line 13: warning 563: Argument #1 is not the correct type.

I went to HP site and check on the sytax for HPUX11 on fgets at:
http://devresource.hp.com/STKL/man/11.00/gets_3s.html
I can not see any problem with the code and it runs with no problems.


Thanks in advance for your help Marty
1 REPLY 1
Kenneth Platz
Esteemed Contributor

Re: HPUX11 fgets() warning

Marty,

The fgets() and fputs() functions expect a pointer to a (signed) char, not a pointer to an unsigned char. This doesn't make much difference to your program, but is sufficient to cause the compiler to generate a warning. You can eliminate these warnings by changing your declaration of "buf" to:

static char buf[1024];

Incidentially, the program as you posted it will actually print nothing, because the line:

while( fgets( buf, 80, infile ) != NULL ) ;

will simply read all of the lines of the infile and do nothing with them. (Ie, you should remove the semicolon at the end of the line).

I hope this helps.
I think, therefore I am... I think!