By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,902 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,902 IT Pros & Developers. It's quick & easy.

Simple Question? Conversion Error.

P: n/a
In this program, it is going to change a value in the array. So to give
it it's new value I need to assign it the new value. It doesn't like
the conversion. Here is the error.

c:\C++\Serendipity\Chapter 9\invmenu.cpp(185): error C2440: '=' :
cannot convert from 'char' to 'char [14]'

Here is the code.

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{
cout << "\nEnter the new ISBN number: ";
cin >> xisbn[14];
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
}

cin gets the letter they input for what category they want to change.
then they have to enter the new isbn number and i want it to assign
that number to the array so its saved. but i keep getting that error.

If someone can point me on the right direction or why it doesn't like
that conversion, that would be great! Thank you very much!

Oct 31 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
GRoll21 wrote:
In this program, it is going to change a value in the array. So to give
it it's its new value I need to assign it the new value. It doesn't like
the conversion. Here is the error.

c:\C++\Serendipity\Chapter 9\invmenu.cpp(185): error C2440: '=' :
cannot convert from 'char' to 'char [14]'

Here is the code.

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{
cout << "\nEnter the new ISBN number: ";
cin >> xisbn[14];
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
}

cin gets the letter they input for what category they want to change.
then they have to enter the new isbn number and i want it to assign
that number to the array so its saved. but i keep getting that error.

If someone can point me on the right direction or why it doesn't like
that conversion, that would be great! Thank you very much!

You have not provided enough context. What is the declaration of `isbn'?
What is the declaration of `xisbn'?

In general, you will be best served by providing *real* code, a minimal
compilable (or something you think *should* be compilable) snippet.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Oct 31 '05 #2

P: n/a
this is the whole function.

void editBook(int a)
{

///////used to hold new values///
char xisbn[14];
char xtitle[51];
char xauthor[51];
char xpublisher[31];
char xdate[11];
int xqty;
float xwholeSale;
float xretail;
/////////////////////////////////

char change;
char lookUp[51];
bool found = false;

system("cls");
cout << "\n\t\tEnter the title of the book you wish to edit ";
cin >> lookUp;
cout <<"\n\n";

for(int index = 0; index < 20 && !found; index++)
{;

// toupper
char up1[51], up2[51];
for(int position=0; position < 51; position++)
{
up1[position] = toupper(lookUp[position]);
up2[position] = toupper(bookTitle[index][position]);
}
if (strcmp(up1, up2) == 0)
{
found = true;
bookinfo(isbn[index], bookTitle[index], author[index],
publisher[index], dateAdded[index], qtyOnHand[index], wholesale[index],
retail[index]);
}

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{ cin.ignore();
cout << "\nEnter the new ISBN number: ";
cin.getline(xisbn,14);
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
cout <<"\n" << xisbn; //test
}
if (change == 'T' || change =='t')
{
}
if (change == 'A' || change =='a')
{
}
if (change == 'P' || change =='p')
{
}
if (change == 'D' || change =='d')
{
}
if (change == 'Q' || change =='q')
{
}
if (change == 'W' || change =='w')
{
}
if (change == 'R' || change =='r')
{
}
}

if(!found)
{
cout << "Book not in Inventory";
}
}

Oct 31 '05 #3

P: n/a
GRoll21 wrote:
this is the whole function.
And which line the error is on?

Learn to post correctly, please. I managed to guess where the error
would be, but next time simply put a comment on the same line.

void editBook(int a)
{

///////used to hold new values///
char xisbn[14]; [...] isbn[index] = xisbn[14]; [...] }


The posted code does not show what 'isbn' is, so no telling about the
assignment being correct. If 'isbn[index]' is, in fact, a pointer to
char, then you cannot assign a char to a pointer to char. There is
also another bad mistake here: an attempt to extract a value from
a location _beyond_ the array bounds. 'xisbn' is an array of 14 chars
and its elements are numbered from 0 to 13. There _is_no_ char at
location 'xisbn[14]'.

Perhaps what you're trying to accomplish is to copy the contents of
the 'xisbn' array into 'isbn[index]' array, then you need to use

strcpy(isbn[index], xisbn);

(if 'isbn[index]' does in fact point to large enough memory block to
contain the characters), however, if I were to do the same thing in
my own program, I'd probably used 'std::string' to keep both 'isbn'
elements and 'xisbn'. IOW

std::string xisbn;

and then the assignment should simply be

isbn[index] = xisbn;

Good luck!

V
Oct 31 '05 #4

P: n/a
sorry i don't come here that much for help so i did not understand how
to correctly post. I now know. and yeah that was the error.. doing the
copy worked just fine.

strcpy(isbn[index], xisbn);

thank you very much for helping.

Oct 31 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.