LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   what is this warning in C? (https://www.linuxquestions.org/questions/programming-9/what-is-this-warning-in-c-108679/)

h/w 10-26-2003 10:01 AM

what is this warning in C?
 
hey - these are some warnings i get and i would like to not see them when i code. it doesnt affect the running of the code, but stilll ...

Code:

implicit declaration of function 'strrchr'
that;s when i write some line like
Code:

char *end, *line;
if ( (end = strrchr (line, ':')) == NULL)

thank you very much again. :)

Y0jiMb0 10-26-2003 12:01 PM

...and, of course, you've added
Code:

#include <string.h>
at the beginning of the program, haven't you?
Regards

h/w 10-26-2003 01:03 PM

of course. :)

megaspaz 10-26-2003 03:04 PM

well your pointers aren't initialized. to you, they look like they're pointing to nowhere, but in reality, where they point to is undefined. they could be pointing to anywhere. always initialize your pointer variables to some value before using them in checks, pointer arithmetic, etc.

not sure about the warning though, if you say <string.h> is included.

Robert0380 10-26-2003 04:12 PM

u must be compiling with -ansi huh?

put a prototype in for strchrr and that might clear it up. same happens with strdup

SaTaN 10-26-2003 10:30 PM

Code:

#include<string.h>
#include<stdio.h>
main()
{
        char *end,*line="This is a :test";
        if((end=strchr(line,':'))!=NULL)
                printf("%s\n",end);
}

[SaTaN@mirage linux_org]$ cc strchr.c
[SaTaN@mirage linux_org]$ ./a.out
:test


This works fine on my machine.Maybe you should post the entire code.

h/w 10-26-2003 11:05 PM

thanks guys - all of y'all.
as i mentioned, it doesnt affect the running of the code. the message only comes up when i compile with -Wall. it doesnt come up with a "gcc -o test test.c".
thanks again. :)

Robert0380 10-26-2003 11:16 PM

put in the prototype anyway!!! :) (all it will do is pass Wall and it will also help it lint with no errors).


All times are GMT -5. The time now is 06:00 AM.