Hi Guys
im getting an error with my code.
Code:
main.cpp invalid conversion from `char' to `const char*'
initializing argument 2 of `int strcmp(const char*, const char*)'
Im trying to read from a 2-dimensional array and Im not too good with strcmp so maybe thats my issue. Originally i was going to use this format:
Code:
if ( pc == list[0][0] )
{
// do somthing
}
But I got a casting char pointer error.
Here is my code
Code:
#include <iostream>
#include <string>
#include <iomanip>
// function prototypes
void itemSelection ( char[][ 80 ] );
void calculatePayment ( char[][ 80 ], char[], unsigned short& );
// main - begins program execution /////////////////////////////////////////////
//
int main(int argc, char *argv[])
{
std::cout << std::setprecision( 2 ) << std::fixed;
// array of 20 strings each can
// hold length of 80 characters
char itemList[ 20 ][ 80 ] =
{
"0120", "Baked Beans",
"0121", "Fish Cakes",
"0122", "Bread",
"0123", "Apple Pie",
"0124", "Milk",
"0125", "Tin Of Peas",
"0126", "Breakfast Cereal",
"0127", "Pactet Of Biscuits",
"0128", "Tea Bags",
"0129", "Meat"
};
itemSelection ( itemList );
std::cin.get(); // freeze console output window
std::cin.ignore();
return 0; // return value from main to OS
}
// function to make a selection from the item list
void itemSelection ( char list[][ 80 ] )
{
int i;
unsigned short itemQuant;
char productCode[ 80 ];
std::cout << "Enter product code: ";
std::cin >> productCode;
for ( i = 0; i < 20; i += 2 )
{
if ( !strcmp ( productCode, list[ i ] ))
{
std::cout << "\nItem is: " << list[ i + 1 ]
<< "\nPlease enter the quantity of this item: ";
std::cin >> itemQuant;
if (( itemQuant <= 0 ) || ( itemQuant > 100 ))
{
std::cout << "\nThe entered amount is negative ot exceeds the\n"
<< "The limit allowed." << std::endl;
}
calculatePayment ( list, productCode, itemQuant );
break;
}
}
if ( i == 10 )
{
std::cout << "\nItem not found!" << std::endl;
}
}
// function to calculate the payment
void calculatePayment ( char list[][ 80 ], char pc[], unsigned short &rQuant )
{
if ( strcmp ( pc, list[0][0] )) // ERROR LINE
{
std::cout << "\n\nWho said that!\n";
}
}
Any help appreiciated, I know its somthing small thats the error but im having trouble correcting it.