function error

This is a discussion on function error within the C++ Programming forums, part of the General Programming Boards category; I can't get this to work! the error-implicit declaration of function 'int getarray(...)' Code: #include <iostream.h> #include <stdlib.h> #include <string.h> ...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Angry function error

    I can't get this to work!
    the error-implicit declaration of function 'int getarray(...)'

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX 15
    #define TAB /t
    
    int main()
    {
          char array[MAX];
          int showall;
          array[MAX]=getarray();
          for(showall=0; showall < MAX; showall++)
          {
                         cout << array[showall-1];
                         cin.get();
          }
          system("PAUSE");
          return 0;
    }
    
    void getarray(char x)
    {
         cout << "Enter an array";
         cin >> x;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    fxns need to be either defined or prototyped above main.

    also, getarray is void, it does not return a value, so array[MAX] = getarray() is wrong. also, getarray() takes a char argument, so you need to pass it something or do not use it. also, you can't do what you want to do with this same line. array[MAX] should give you out of bound errors as well, also with the line array[showall - 1].

    rethink this.

  3. #3
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    thx. I'm a little new with functions.

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    here is my edited code.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX 20
    #define TAB /t
    
    void getarray(char x)
    {
         cout << "Enter an array" << endl;
         cin >> x;
    }
    int main()
    {
          char array[MAX];
          int showall;
          getarray(array[MAX]);
          for(showall=0; showall < MAX; showall++)
          {
                         cout << array[showall];
                         cin.get();
          }
          system("PAUSE");
          return 0;
    }
    now it compiles but is just a bunch of jumbled up characters

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    getarray(array[MAX]);

    this line is wrong. you should use a loop to get the characters. also, you need to use a reference parameter for x, otherwise it won't alter the value.

  6. #6
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    What exactly do you want to achieve cause from the code u made its not very clear and doesnt seem logic..

    if u want to fill the array one character at a time say so and ill help u with that

    if its not that i dunno what u wanna do..

    ofc im stoned now so that might be the reason i dont get it
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    102
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX 20
    #define TAB /t
    
    void getarray(char x[])
    {
         cout << "Enter an array" << endl;
         cin >> x;
    }
    int main()
    {
          char array[MAX] ={0};
    // Initalize the array to 0 just for fun (ie clear out all that junk)
          int showall;
          getarray(array); // Pass array so that it can be read in to by getarray()
          for(showall=0; showall < MAX; showall++)
          {
                         cout << array[showall];
                         cin.get();
    // I have to admit I dont know C++ all that well but what is this for?? 
    //It looks like its trying to get a char? is that to pause when ever you print a char?
    
          }
          system("PAUSE");
          return 0;
    }
    My C has gotten rusty.. If i made any mistakes let me know.
    Also I though that the code cin >> array would grab the array?
    Im I wrong about that?

  8. #8
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    Squid:
    yes cin>>array would do that but thats not what he does..
    cin >> x..
    and x is only one char..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    102
    Thats what I though.. I just realized that and edited his code to make it an array. Have I messed it up at all?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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