A simple array question

This is a discussion on A simple array question within the C++ Programming forums, part of the General Programming Boards category; If you put a array in the intialiaztion of a function, do you have to put an array when you ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    A simple array question

    If you put a array in the intialiaztion of a function, do you have to put an array when you call it? Because I am getting an error that says something lacks a cast. Is there any way around this?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    dont really understand the question.... if you would post the func. declaration,implementation and a small example of you calling it i could be more help.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Code:
    int NumberLine(int number[4],int xpos,int ypos)
    {
     int digit1=number[0];
     int digit2=number[1];
     int digit3=number[2];
     int digit4=number[3];
     int digit5=number[4];
     BITMAP one;
     BITMAP two;
     BITMAP three;
     BITMAP four;
     BITMAP five;
     BITMAP six;
     BITMAP seven;
     BITMAP eight;
     BITMAP nine;
     BITMAP space;
     BITMAP zero;
     load_bmp("0.bmp",&zero);
     load_bmp("1.bmp",&one);
     load_bmp("2.bmp",&two);
     load_bmp("3.bmp",&three);
     load_bmp("4.bmp",&four);
     load_bmp("5.bmp",&five);
     load_bmp("6.bmp",&six);
     load_bmp("7.bmp",&seven);
     load_bmp("8.bmp",&eight);
     load_bmp("9.bmp",&nine);
     load_bmp("space.bmp",&space);
     switch (digit1)
     {
     case '0':
     draw_transparent_bitmap(&zero,xpos,ypos);
     xpos=xpos+12;
     break;
     case '1':
     draw_transparent_bitmap(&one,xpos,ypos);
     xpos=xpos+12;
     break;
     case '2':
     draw_transparent_bitmap(&two,xpos,ypos);
     xpos=xpos+12;
     break;
     case '3':
     draw_transparent_bitmap(&three,xpos,ypos);
     xpos=xpos+12;
     break;
     case '4':
     draw_transparent_bitmap(&four,xpos,ypos);
     xpos=xpos+12;
     break;
     case '5':
     draw_transparent_bitmap(&five,xpos,ypos);
     xpos=xpos+12;
     break;
     case '6':
     draw_transparent_bitmap(&six,xpos,ypos);
     xpos=xpos+12;
     break;
     case '7':
     draw_transparent_bitmap(&seven,xpos,ypos);
     xpos=xpos+12;
     break;
     case '8':
     draw_transparent_bitmap(&eight,xpos,ypos);
     xpos=xpos+12;
     break;
     case '9':
     draw_transparent_bitmap(&nine,xpos,ypos);
     xpos=xpos+12;
     break;
     }
      switch (digit2)
     {
     case '0':
     draw_transparent_bitmap(&zero,xpos,ypos);
     xpos=xpos+12;
     break;
     case '1':
     draw_transparent_bitmap(&one,xpos,ypos);
     xpos=xpos+12;
     break;
     case '2':
     draw_transparent_bitmap(&two,xpos,ypos);
     xpos=xpos+12;
     break;
     case '3':
     draw_transparent_bitmap(&three,xpos,ypos);
     xpos=xpos+12;
     break;
     case '4':
     draw_transparent_bitmap(&four,xpos,ypos);
     xpos=xpos+12;
     break;
     case '5':
     draw_transparent_bitmap(&five,xpos,ypos);
     xpos=xpos+12;
     break;
     case '6':
     draw_transparent_bitmap(&six,xpos,ypos);
     xpos=xpos+12;
     break;
     case '7':
     draw_transparent_bitmap(&seven,xpos,ypos);
     xpos=xpos+12;
     break;
     case '8':
     draw_transparent_bitmap(&eight,xpos,ypos);
     xpos=xpos+12;
     break;
     case '9':
     draw_transparent_bitmap(&nine,xpos,ypos);
     xpos=xpos+12;
     break;
     }
     switch (digit3)
     {
     case '0':
     draw_transparent_bitmap(&zero,xpos,ypos);
     xpos=xpos+12;
     break;
     case '1':
     draw_transparent_bitmap(&one,xpos,ypos);
     xpos=xpos+12;
     break;
     case '2':
     draw_transparent_bitmap(&two,xpos,ypos);
     xpos=xpos+12;
     break;
     case '3':
     draw_transparent_bitmap(&three,xpos,ypos);
     xpos=xpos+12;
     break;
     case '4':
     draw_transparent_bitmap(&four,xpos,ypos);
     xpos=xpos+12;
     break;
     case '5':
     draw_transparent_bitmap(&five,xpos,ypos);
     xpos=xpos+12;
     break;
     case '6':
     draw_transparent_bitmap(&six,xpos,ypos);
     xpos=xpos+12;
     break;
     case '7':
     draw_transparent_bitmap(&seven,xpos,ypos);
     xpos=xpos+12;
     break;
     case '8':
     draw_transparent_bitmap(&eight,xpos,ypos);
     xpos=xpos+12;
     break;
     case '9':
     draw_transparent_bitmap(&nine,xpos,ypos);
     xpos=xpos+12;
     break;
     }
     switch (digit4)
     {
     case '0':
     draw_transparent_bitmap(&zero,xpos,ypos);
     xpos=xpos+12;
     break;
     case '1':
     draw_transparent_bitmap(&one,xpos,ypos);
     xpos=xpos+12;
     break;
     case '2':
     draw_transparent_bitmap(&two,xpos,ypos);
     xpos=xpos+12;
     break;
     case '3':
     draw_transparent_bitmap(&three,xpos,ypos);
     xpos=xpos+12;
     break;
     case '4':
     draw_transparent_bitmap(&four,xpos,ypos);
     xpos=xpos+12;
     break;
     case '5':
     draw_transparent_bitmap(&five,xpos,ypos);
     xpos=xpos+12;
     break;
     case '6':
     draw_transparent_bitmap(&six,xpos,ypos);
     xpos=xpos+12;
     break;
     case '7':
     draw_transparent_bitmap(&seven,xpos,ypos);
     xpos=xpos+12;
     break;
     case '8':
     draw_transparent_bitmap(&eight,xpos,ypos);
     xpos=xpos+12;
     break;
     case '9':
     draw_transparent_bitmap(&nine,xpos,ypos);
     xpos=xpos+12;
     break;
     }
     switch (digit5)
     {
     case '0':
     draw_transparent_bitmap(&zero,xpos,ypos);
     xpos=xpos+12;
     break;
     case '1':
     draw_transparent_bitmap(&one,xpos,ypos);
     xpos=xpos+12;
     break;
     case '2':
     draw_transparent_bitmap(&two,xpos,ypos);
     xpos=xpos+12;
     break;
     case '3':
     draw_transparent_bitmap(&three,xpos,ypos);
     xpos=xpos+12;
     break;
     case '4':
     draw_transparent_bitmap(&four,xpos,ypos);
     xpos=xpos+12;
     break;
     case '5':
     draw_transparent_bitmap(&five,xpos,ypos);
     xpos=xpos+12;
     break;
     case '6':
     draw_transparent_bitmap(&six,xpos,ypos);
     xpos=xpos+12;
     break;
     case '7':
     draw_transparent_bitmap(&seven,xpos,ypos);
     xpos=xpos+12;
     break;
     case '8':
     draw_transparent_bitmap(&eight,xpos,ypos);
     xpos=xpos+12;
     break;
     case '9':
     draw_transparent_bitmap(&nine,xpos,ypos);
     xpos=xpos+12;
     break;
     }
    
    }
    
    NumberLine(maincharacter.bHP,50,50);
    I know, I am going to shrink the function later. The function compiles ok, it's supposed to, nothing is wrong with the function. But when I call it using a variable, with an array or not, it says the variable lacks a cast.

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    ?

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    didnt look any further than this...
    int digit5=number[4];

    there is no number[4]....

    look at the dec....

    int NumberLine(int number[4],int xpos,int ypos)

    a function that returns an int and takes an array of ints of only this size[4] and two other ints.

    so as array size is [4] top array element is [3]

    fix that first. then post again and include def of mainchar struct.
    Last edited by Stoned_Coder; 11-25-2001 at 10:18 AM.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    english please

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    1) you have specified that you can only call this function with an array[4]

    you cant call it with an array[3] or an array[5]. Get the picture.

    2) You are accessing past the bounds of your array..... see previous post.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    look, dude I am not having any problems with the ints, ok. It is only when I call the function. If I put "1234" where I put maincharacter.bATK, it works just fine. But if I throw a variable in there, it doesn't want to work. I tried a array in the place of it, and it gave me a different error, saying invalid types.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hopefully simple question, input streams
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2006, 01:59 PM
  2. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  3. simple array question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2002, 10:43 PM
  4. simple array question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 04:46 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21