function&arrays - please help...

This is a discussion on function&arrays - please help... within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a program using functions and arrays..... It needs to recieve a character array buff of ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Unhappy function&arrays - please help...

    I am trying to make a program using functions and arrays.....

    It needs to recieve a character array buff of 6 characters. This would be entered by the user. Then the character array buff needs to be printed in the function...
    for example
    please enter information ==> 123456
    output:
    buff[0]==> 1
    buff[1]==> 2
    and so on

    This is what i have so far.
    #include<iostream.h> // need this!
    #include<math.h> // need this!

    int main() // need this!
    { // need this!

    const char NUMBER = 6; // array declaration
    int FUNPROT(int[NUMBER]); // function prototype

    char code[NUMBER]; // array declaration
    int FUNPROT(int[NUMBER]); // function prototype

    char code[NUMBER]; // array declaration
    int i;

    // so that it repeats only 6 times.. if this wasnt here it would repeat forever
    for(i=0; i<NUMBER; i++);
    {
    cout<<"Enter input here==>";

    cin>>code[i];
    }
    int FUNPROT(int vals[NUMBER])
    {
    // print out character array in function
    for(i=0; i<NUMBER; i++); // print out the number entered
    }
    }

    I'm a little confused... any help would be appreciated.

    thank you

    marie10913@aol.com

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    PHP Code:

    #include <iostream.h> // need this for Input/Output

    // global variables and constants
    const int NUMBER 6;

    // function prototypes
    void FUNPROTchar vals[NUMBER] ); // function prototype 

    int main()
    {
         
    // variable declaration 
        
    char code[NUMBER];
        
    int i

        
    //code
        
    for( 0NUMBERi++ )
        { 
           
    cout << "Enter input #" << << " here:" << flush
           
    cin >> code[i]; 
        }

        
    FUNPROTcode );

        return 
    0;
    }

    // function implementation
    void FUNPROTchar vals[NUMBER] ) 
    {
        
    // variable declaration 
        
    int i;

        
    // code
        
    for( NUMBER i++ )
        {
            
    cout << "Input " << << " was: " << vals[i] << endl;
        }

    You have mixed up your types and prototypes and had some things in there twice. Make sure you know what you need those parts for that said "//need this!".
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    21
    yeah, prototypes area always over the main()
    i guess ur having problems passing an array to the function, dont u????
    well, to do so, u dont have to put the [x] to thearray. i mean:

    function(hello[50], y); isnt correct. u go:

    function(hello, y);


    the reazon of been this way is that in the prototype:
    void function(char [], int);
    u define, that the first entrance will be an array....

    oh,... an other thing.
    when u make a define, u dont put

    #define int NAME= 6

    u go:

    #define NAME 6

    hope it worked....

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Talking thank you -- one more question

    the help i have recieved was great...

    i just have one question about the suggestion...

    cout << "Enter input #" << i + 1 << " here:" << flush;

    on this line what does flush mean or do...

    thank you

    marie10913@aol.com

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    flush

    You can leave it out. It just means that this line has to be printed right then. It must not be buffered. Just leave it out, you don't need it.

    Just delete the "<< flush" part.

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

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