LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2008, 09:29 AM   #1
christyyim
Member
 
Registered: Oct 2008
Location: earth
Distribution: Ubuntu 'Gutsy Gibbon'
Posts: 32

Rep: Reputation: 15
"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:

Quote:
warning: assignment makes integer from pointer without a cast
Here is my code:

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 ( fgetslinesizeof linefp))
  {
    
printf("%s"line);
  }
  
pclose(fp);

  
pch strtok (line,"     ");
  for (
m=0m<2m++)
  {
    
pch strtok (NULL"     ");
  }
    
printf ("%s\n",pch);
  
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.
 
Old 12-23-2008, 09:57 AM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
Cast, Rewrite, or Ignore

I am assuming this line is the offending line:

while ( fgets( line, sizeof line, fp))

fgets returns a char pointer. Either cast the result to an integer, ignore the warning, or rewrite to assign fgets to a pointer variable and test that.
 
Old 12-23-2008, 10:02 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The error is in the line:
Code:
b = pch;
'b' is and int, and 'p' is pointer to char. That is not correct syntax.

Assuming you are trying to have 'b' set to indicate whether 'pch' is a NULL pointer, you should change the line to:
Code:
b = (NULL==pch);
I wonder though why you are implementing a shell script in C....
 
Old 12-23-2008, 10:13 AM   #4
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Rep: Reputation: 16
Quote:
Originally Posted by Hko View Post
The error is in the line:
Code:
b = pch;
'b' is and int, and 'p' is pointer to char. That is not correct syntax.

Assuming you are trying to have 'b' set to indicate whether 'pch' is a NULL pointer, you should change the line to:
Code:
b = (NULL==pch);
I wonder though why you are implementing a shell script in C....
There is a typo there which would result in the incorrect behaviour. A number of options are available here.
Code:
 b = pch?1:0; b = pch!=NULL;/*Hko's fixed*/ b = !!pch;
 
Old 12-23-2008, 11:42 AM   #5
christyyim
Member
 
Registered: Oct 2008
Location: earth
Distribution: Ubuntu 'Gutsy Gibbon'
Posts: 32

Original Poster
Rep: Reputation: 15
First of all, thanks for the replies from you all. And I just found out that I had misunderstood the way how strtok works and cause me write this program which may sound stupid to you all. hehe.. And now i'll rewrite the program again. Thanks for help.

Quote:
Originally Posted by Hko View Post

I wonder though why you are implementing a shell script in C....
The reason I implement a shell script in C because this is the only way I found out so far which will let me know whether the LAN cable is plugged or unplugged. Or does anyone has any advice for me? Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast nasim751 Programming 2 02-10-2008 10:47 PM
warning: passing argument 2 of ‘memset’ makes integer from pointer without a cast nasim751 Programming 3 01-30-2008 09:16 AM
makes pointer from integer without a cast ? hubabuba Programming 2 01-28-2005 05:28 PM
pointer from integer without a cast bcf2 Programming 7 12-30-2004 02:04 PM
Passing arg 3 of blah makes pointer from integer without a cast xconspirisist Programming 6 08-22-2004 08:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration