unable to print cstring from a function
Write your question here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <ctype.h> // for toupper //
#define MAX_CHAR 256
using namespace std;
char printHeader(char input);
char get_item();
void run_shopping_cart_program();
int main(int argc, const char * argv[])
{
char input = '\0';
bool quit = false;
while (!quit) {
input = printHeader(input);
switch (toupper(input)) {
case 'A':
run_shopping_cart_program();
break;
case 'B':
cout << "Goodbye" << endl;
return quit;
break;
default:
cout << "That is not a vaild option "
<< endl;
}
}
return 0;
}
char printHeader(char input){
cout << "Welcome to your shopping cart programd"
<< endl
<< "Please select (a) to go shopping"
<< endl
<< "Please select (b) to quit"
<< endl;
cin >> input;
return input;
}
char get_item(){
char item_Name[MAX_CHAR+1];
cout << "Please, enter name of item you would like "
<< "to purchase"
<< endl;
cin.getline (item_Name, MAX_CHAR ,'\n');
cin.ignore(MAX_CHAR, '\n');
return item_Name[MAX_CHAR];
}
void run_shopping_cart_program(){
char item[MAX_CHAR+1] = {'\0'};
item[MAX_CHAR] = get_item();
cout << item[MAX_CHAR] << "here........" << endl;
}
|
line 72
cout << item[MAX_CHAR] << " here........" << endl;
assuming "foo Bar" for input.
desired output
foo Bar here........
actual output
¿here........
Thank you in advance for any help or direction!
Topic archived. No new replies allowed.