C programming error. warning: comparison between pointer and integer
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
8 int i = 0;
9 char single_char;
10 char *word[30];
11 f=popen("ifconfig", "r");
12 while(!feof(f))
13 {
14 single_char = fgetc(f);
15 if (single_char != " ")
16 {
17 *word[i] = single_char; /*make a word */
18 i++;
19 }
20 else
21 {
22 i = 0; /*a word has ended, so reset the counter */
23 printf("%s", &word);
24 }
25 }
26 pclose(f);
27 return(0);
28 }
===========================================
I got an error when compile and the message is:
test3.c:15: warning: comparison between pointer and integer
It is complaining on line 15.
if (single_char != " ")
On the above code, I wan to know if a character is a space or not a space.
you need to make sure that you don't try to access anything past word[29]. A segmentation faul is when you try to access memory that you shouldn't, and is a common problem with pointers. (I didn't look too carefully, there could be other places that it would seg fault too)
oh, char *word[30] is probably not what you want, if you're thats an array of 30 char pointers (and you're not allocating any space to use any of them, which is why its seg faulting)
<edit>
I've confirmed that with
&& i < 30
in the while statement
and by removing the * from both instanaces of word it will run to completion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.