LinuxQuestions.org
Visit Jeremy's Blog.
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 08-25-2006, 06:03 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

Rep: Reputation: 30
c warnings


Hi,
these warnings correspond to the following functions. Unfortunately, i can't fix them and get a "segmentation fault". Can somebody help?

Code:
kostas@vakhos:~/c_programming$ gcc -o res res.c
res.c: In function ‘get_cmdline_name’:
res.c:213: warning: return makes pointer from integer without a cast
res.c: In function ‘get_stat_name’:
res.c:234: warning: comparison between pointer and integer
res.c:237: warning: assignment makes integer from pointer without a cast
res.c:237: warning: assignment makes integer from pointer without a cast
res.c:241: warning: assignment makes integer from pointer without a cast
res.c:241: warning: return makes pointer from integer without a cast
Code:
...
char full_path[80];
...
char get_cmdline_name(int proc_id)
{	
	char cmd[360];
	char proc_id_str[64];	

	initialize_buffer(cmd);
	initialize_buffer(full_path);
	initialize_buffer(proc_id_str);

	FILE* f;
	sprintf(proc_id_str, "%d", proc_id);

	strcat(full_path, "/proc/");	
	strcat(full_path, proc_id_str);
	strcat(full_path, "/cmdline");	
	

	if ((f=fopen(full_path,"r"))!=NULL)
	{
		fscanf(f,"%s", cmd);
	}

	return cmd;
}

char get_stat_name(int proc_id)
{	
	char cmd[360];
	char proc_id_str[64];

	initialize_buffer(cmd);
	initialize_buffer(full_path);
	initialize_buffer(proc_id_str);

	FILE* f;
	sprintf(proc_id_str, "%d", proc_id);
	
	strcat(full_path, "/proc/");
	strcat(full_path, proc_id_str);
	strcat(full_path, "/stat");	
	
	char ch='\0';
	if ((f=fopen(full_path,"r"))!=NULL)
	{
		while (ch!='\n')
		{
			ch= (char)fgetc(f);
			if ((ch='(') && (ch=')'))
			{
				ch= (char)fgetc(f);
				strcat(cmd, &ch);
				if (ch=")") 
					return cmd;
			}
		}
	}

	return "\0";
}
 
Old 08-25-2006, 07:45 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
res.c: In function ‘get_cmdline_name’:
res.c:213: warning: return makes pointer from integer without a cast
Code:
char get_cmdline_name(int proc_id)
{
char cmd[360];
...
return cmd;
}
The name of an array is a pointer to the first element. As shown above in get_cmdline_name you are returning a char pointer, this can be fixed by changing the return type to "char*".


In get_stat_name you a have similar problem although this time you have two return paths one which returns a char pointer and one which returns a char(eof which shows a failure). You may fix this using the same mathod as the first but on failure return a 0/NULL.
Also in get_stat_name you have a typo
Quote:
if (ch=")")
should read
Quote:
if (ch==')')
and a logic and typo error above that
Quote:
if ((ch='(') && (ch=')'))
You are checking one char and wanting it to be two values?Well actually you are assigning the values(thats the typo).

Last edited by dmail; 08-25-2006 at 07:52 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Gdk warnings BroX Slackware 5 03-13-2006 06:06 PM
Warnings from make Conjurer Linux - Software 1 11-12-2005 03:10 AM
Need help with java warnings Hockeyfan Programming 1 07-22-2005 03:01 PM
Synaptic warnings snowy MEPIS 6 07-08-2005 04:40 AM
removing warnings h/w Programming 6 01-26-2004 06:06 PM


All times are GMT -5. The time now is 10:03 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration