LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-05-2012, 12:10 AM   #1
chinabenjamin66
Member
 
Registered: Mar 2012
Location: Shenzhen Chian
Posts: 73

Rep: Reputation: Disabled
Error: invalid operands to binary & (have ‘char *’ and ‘int’)


Hello friends,

I am learning C programming under linux recently, this is a example I tried, but got an error.
Code:
 1 /* Insurance of driver - using logical operators */
  2 #include <stdio.h>
  3  main()
  4 {
  5         char sex, ms;
  6         int age;
  7         printf("Enter age, sex, marital status");
  8         scanf("%d %c %c" &age, &sex, &ms);
  9         if((ms == 'M') || (ms == 'U' && sex == 'M' && age > 30) || (ms == 'U' && sex == 'F' && age >25))
 10                 printf("Driver is insured");
 11         else
 12                 printf("Driver is not insured");
 13 }
~  
root@gpl-vm:/lianxi/ch2# gcc -o insure insure.c 
insure.c: In function ‘main’:
insure.c:8:19: error: invalid operands to binary & (have ‘char *’ and ‘int’)
root@gpl-vm:/lianxi/ch2# vim insure.c 
root@gpl-vm:/lianxi/ch2#
the Linux distribution is

Code:
root@gpl-vm:/lianxi/ch2# cat /proc/version
Linux version 3.2.0-31-generic-pae (buildd@roseapple) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #50-Ubuntu SMP Fri Sep 7 16:39:45 UTC 2012
How to deal with this?
 
Old 12-05-2012, 12:37 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
probably you missed a , before &age.
scanf("%d %c %c", &age, &sex, &ms);
 
Old 12-05-2012, 12:43 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by chinabenjamin66 View Post

How to deal with this?
Simple. The compiler gives you a hint that there is a problem in line 8. If you carefully read that line you will realize that you are missing a comma.

Edit: Too late.

Last edited by TobiSGD; 12-05-2012 at 12:44 AM.
 
Old 12-05-2012, 12:54 AM   #4
chinabenjamin66
Member
 
Registered: Mar 2012
Location: Shenzhen Chian
Posts: 73

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
Simple. The compiler gives you a hint that there is a problem in line 8. If you carefully read that line you will realize that you are missing a comma.

Edit: Too late.
Thanks, I am a beginer for C programing under linux, some questions I asked may be silly or very simple. hope post valuable question gradually.
 
Old 12-05-2012, 01:36 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
great! you are not silly, just made a mistake. Try to interpret the error message and look for strange things (like "binary &")
And press YES (bottom right corner) if you really want to say 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
compile error: invalid operands for binary >> for pgd_index(addr) macro rashmikant Linux - Kernel 1 06-10-2009 03:36 PM
getting error: invalid conversion from ‘const char*’ to ‘int’ while compling paulie1 Programming 14 02-25-2009 02:50 PM
C++ atoi error: invalid conversion from `int' to `const char*' bakana Programming 2 02-24-2009 03:29 AM
Error: suffix or operands invalid for `push' in 64 machine arya Linux - General 1 04-19-2007 10:32 AM
what does "prog7.c:11: error: invalid operands to binary %" mean hubabuba Programming 6 11-16-2004 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:21 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