char checkInput[80];
cout<<"Input Anything: ";
cin>>checkInput;
if((checkInput[0]=='e')&&(checkInput[1]=='x')&&(checkInput[2]=='i')&&(checkInput[3]=='t')){
exit (0); //terminates the program
}//end if
else{
char * character = checkInput;
return (character);
}//end else
}//end userInput function
-----------------------------------------------------------------------
what is the proper way of returning an array using a pointer?
I need to pass the array in userInput function to main.
How? I'm still confused with pointers to arrays thx.
Can someone edit my code to make it run properly? thx.
what is the proper way of returning an array using a pointer?
Generally, there isn't one. You don't return arrays.
You're better off passing a pointer to the buffer to the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void userInput(char* checkInput)
{
// do stuff here
// write to checkInput as if it were a normal array
}
int main()
{
char input[80];
// get user input
userInput( input );
// stuff here
}
Although -- screw char arrays. Save yourself the headaches and buffer overflows and use std::string:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string userInput()
{
string checkInput;
// do stuff with checkInput here
return checkInput;
}
int main()
{
string input = userInput;
// etc
}