Thread: Getting error: invalid operands to binary &

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    10

    Getting error: invalid operands to binary &

    Hello!
    I have a problem: i ask some information fron the user, but when I compile the program, it shows that there is mistake in data entry and gives error message: invalid operands to binary &
    Help and tips would be very helpful

    a piece of code, that the problem is :
    (and sorry for my bad english, hope you understand )

    Code:
    #include <stdio.h>
    #include <malloc.h>
    #include <string.h>
    
    //Põhiprogramm
    main()
    {
       int I, L, H;
       char R[50], E[50], P[50], T[50], K[50];
       printf("Sisesta raamatu nimi: ");
       scanf("%s" &R);
       printf("\n");
       printf("Sisesta raamatu ilmumisaasta: ");
       scanf("%d" &I);
       printf("\n");
       printf("Sisesta raamatu lehekülgede arv: ");
       scanf("%d" &L);
       printf("\n");
       printf("Sisesta raamatu autori eesnimi: ");
       scanf("%s" &E);
       printf("\n");
       printf("Sisesta raamatu autori perekonnanimi: ");
       scanf("%s" &P);
       printf("\n");
       printf("Sisesta raamatu keel (nt. est, eng): ");
       scanf("%s" &K);
       printf("\n");
       printf("Kas oled lugenud seda raamatut (loetud/lugemata): ");
       scanf("%s" &T);
       printf("\n");
       printf("Sisesta raamatu hinne (1 - 10): ");
       scanf("%d" &H);
       printf("\n\n");
       
       system("pause");
    }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You're missing a comma inside each scanf, to separate the two arguments.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    10
    Quote Originally Posted by iMalc View Post
    You're missing a comma inside each scanf, to separate the two arguments.
    OK, i didn't see that. Little mistake and everything is wrong ...
    Thank you!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > #include <malloc.h>
    This is an obsolete header file, avoid using it.

    > main()
    main returns an int, so say int main()
    Old C would assume that main returned an int, but all "implicit int" behaviour has been removed from modern C, so it's best to get into the habit of being specific.

    > scanf("%s" &R);
    There is no need to use & when using %s with a char array.
    Use instead scanf("%s",R);

    Also, pick meaningful variable names.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-26-2009, 10:07 AM
  2. Invalid Operands to Binary Error
    By MikeyVeeDubb in forum C Programming
    Replies: 17
    Last Post: 09-23-2009, 04:13 AM
  3. error: invalid operands to binary %
    By OxKing033 in forum C Programming
    Replies: 12
    Last Post: 03-18-2008, 09:21 AM
  4. error: invalid operands to binary *
    By cblix in forum C Programming
    Replies: 5
    Last Post: 01-29-2006, 08:45 PM
  5. invalid operands to binary %
    By Mathsniper in forum C Programming
    Replies: 3
    Last Post: 12-03-2005, 11:21 PM