Results 1 to 5 of 5
Here is the code I wrote to detect whether a LAN cable is pluged or unpluged. After compilation, it gives me the warning:
warning: assignment makes integer from pointer without ...
- 12-23-2008 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 25
"warning: assignment makes integer from pointer without a cast" in C
Here is the code I wrote to detect whether a LAN cable is pluged or unpluged. After compilation, it gives me the warning:
Here is my code:warning: assignment makes integer from pointer without a cast
PHP Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define yes 1
#define no 0
typedef int boolean;
int main()
{
FILE *fp;
char *pch;
char line[130]; /* line of easa!from unix command*/
int m;
boolean b;
fp = popen("nm-tool | grep Link", "r"); /* Issue the command. */
/* Read a line */
while ( fgets( line, sizeof line, fp))
{
printf("%s", line);
}
pclose(fp);
pch = strtok (line," ");
for (m=0; m<2; m++)
{
pch = strtok (NULL, " ");
}
printf ("%s\n",pch);
b = pch;
printf("%d\n",b); /* more to add on */
return 0;
}
I have googled some solutions online, like include the stdlib.h header and etc but all didn't work. Does anyone has any idea on it?
Thanks in advance.
- 12-23-2008 #2
i'm not a C programmer, but it seems to me that you are trying to assign a char pointer to a boolean with b = pch, when pch is a character pointer and b is a boolean
- 12-23-2008 #3Just Joined!
- Join Date
- Nov 2008
- Posts
- 25
thanks coopstah13. The reason i did so is because the pch i get in the end will be either yes or no and since i had defined yes and no to 1 and 0 respectively before the main program, that is why i assigned it to a boolean with b=pch.
Even though i also agree with you that the warning is most probably because of this assignment, but I have no idea on how to solve it as I'm a beginner to C programming.
- 12-23-2008 #4
Who said that?
strtok will return a pointer to char. Therefore, pch will be of the value NULL or non NULL. Finding Tokens in a String - The GNU C Library
So if you want b to be 1 in case pch is non-null, you need something like
b = (pch != NULL);Debian GNU/Linux -- You know you want it.
- 12-23-2008 #5Just Joined!
- Join Date
- Nov 2008
- Posts
- 25
yah, GNU-Fan, you hit the nail on the head!!! Thanks

I misunderstood the way how strtok works. And now i use strstr function instead of strtok. Thanks.


Reply With Quote
