Thread: [warning] strcpy makes pointer from integer without a cast

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    6

    [warning] strcpy makes pointer from integer without a cast

    Hi! I'm new to CBoard and to programming so please bear with me. Imma noob.

    Suppose I have this structure for Costumer Account:

    Code:
    typedef struct
    {
          char account[6];
          int balance;
    }COSACC;
    And I have to compare the balance from something inputted.

    Code:
    printf("\n\nEnter New Balance: ");
    scanf("%d", &ab);
    strcpy(y[i].balance, ab);
    How do I do something like that as to not get a warning? Thanks so much!

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Could you post more of your code please?
    What is the y and ab declared as?
    You get this warning because you do not pass the arguments as you should.You have to keep in mind the prototype of strcpy strcpy - C++ Reference.There is also an example there

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Since balance is an int not a C-string you would do something like:
    Code:
    y[i].balance = ab;
    // or without the intermediate variable.
    scanf("%d", &y[i].balance);
    The strcpy() function only works with nul terminated character strings.


    Jim

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Just get rid of strcpy() altogether and compare the two integers in your code.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    They aren't strings, so all you probably wanted was:
    Code:
    y[i].balance = ab;
    However, if that's all you're doing, then you don't need the variable ab at all. You could just read straight into the desired location, in two lines, like this:
    Code:
    printf("\n\nEnter New Balance: ");
    scanf("%d", &y[i].balance);
    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"

  6. #6
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    Quote Originally Posted by iMalc View Post
    They aren't strings, so all you probably wanted was:
    Code:
    y[i].balance = ab;
    However, if that's all you're doing, then you don't need the variable ab at all. You could just read straight into the desired location, in two lines, like this:
    Code:
    printf("\n\nEnter New Balance: ");
    scanf("%d", &y[i].balance);
    Thank you! This was all I needed to do.

    Sorry it took me this long to reply. I'm swamped with projects and darn tests. Thanks for all your help, guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strcpy makes pointer from integer without a cast?
    By Kalastrian in forum C Programming
    Replies: 11
    Last Post: 01-07-2012, 06:37 AM
  2. Replies: 4
    Last Post: 02-12-2011, 07:33 PM
  3. Replies: 3
    Last Post: 04-24-2010, 04:41 PM
  4. Replies: 4
    Last Post: 03-03-2010, 01:06 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM

Tags for this Thread