473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Cannot convert from char[20][40] to char*

This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #1
7 5309
"GRoll35" <mi**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(bookTitle[index], 40); is probably what you
meant.
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #2

"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:KP***************@fe02.lga...
"GRoll35" <mi**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(bookTitle[index], 40); is probably what you
meant.


er, I think it has to be cin.getline(&bookTitle[index], 40);
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Nov 22 '05 #3
thanks Jim. That fixed that error now I get all these.. I'm guessing
they are all connected to the same thing..

ser6 fatal error LNK1120: 2 unresolved externals
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3PAY09DA)
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3PAY09DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3PAY0CI@DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3PAY0CI@DA)

im playing around with it to see what it could be.. any idea?

Nov 22 '05 #4
GRoll35 wrote:
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;
Don't declare variables until you need them, and then declare them in
as small a scope as possible. You never use "quant", and "tax" should
be const.

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
Global variables?! Try passing parameters to your function instead.


do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Try:

cin.getline( bookTitle[index], 40 );
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Cheers! --M

Nov 22 '05 #5
Jim Langston <ta*******@rocketmail.com> wrote:
"Jim Langston" <ta*******@rocketmail.com> wrote in message

"GRoll35" <mi**********@gmail.com> wrote in message
extern char bookTitle[20][40]; cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//


Pick an element. cin.getline(bookTitle[index], 40); is probably
what you meant.


er, I think it has to be cin.getline(&bookTitle[index], 40);


Well, if bookTitle[index] really does not work (tho I think it
should), then &bookTitle[index][0] would be correct for sure.

regards
--
jb

(reply address in rot13, unscramble first)
Nov 22 '05 #6
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

Nov 22 '05 #7
GRoll35 wrote:
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]


Quote the code you have now. I'm guessing that you have

int cashier(char bookTitle[20][40])
{
....
cin.getline(bookTitle, 40);

but of course I could be wrong.

To solve this yourself remember that bookTitle is an array of titles, so
to input a title you have to say which title in the array of titles
you are trying to input, i.e.

cin.getline(bookTitle[index], 40);

or something.

john
Nov 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stijn Goris | last post by:
hi all, I have a site where a user can enter text (newspost). I recently discovered that when %20 is entered the text is properly inserted in the database (INSERT) but isn't shown on the page...
2
by: Ralph Smith | last post by:
I'm having trouble copying a database to another machine. Here are the two table's in ths database and the sql commands: DROP TABLE IF EXISTS `clients`; CREATE TABLE `clients` ( `client_id`...
17
by: Magix | last post by:
Hi, How do I set the char to empty ? let say I have, char test; can I do like this : *test = NULL;
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
6
by: Rick | last post by:
Hi guys, i've seen it in VC++ but in C# how do i conver string to char?? in c++ is like http://support.microsoft.com/?kbid=311259 Regards
1
by: Elhanan | last post by:
hi.. sorry for the cross posting, i'm simply not sure where this goes (i'm still genrating this from an asp page). i'm trying to printout normal text from IE using Generic Text Driver like...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
5
by: oliver.andrich | last post by:
Hi, can anybody with ctypes experience tell me, how to handle a C function that returns an unsigned char*? Obviously it is not a restype of c_char_p. Best regards, Oliver
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.