473,386 Members | 1,958 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,386 software developers and data experts.

Simple Question? Conversion Error.

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
4 1936
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nicolay Korslund | last post by:
Hi! I'm having a little trouble with the typecast operator, can anybody help me with the rules for when the this operator is invoked? In the class 'Test' in the code below, the typecast operator...
18
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include...
30
by: zexpe | last post by:
I have an extremely cpu/data intensive piece of code that makes heavy use of the following function: void convertToDouble(const std::string& in, double& out) { out = atof(in.c_str()); } I...
0
by: Rich | last post by:
(1) Is there a better place to pose the question below? (2) I am starting to convert my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 Professional (.NET v2.0.50727). The entire...
29
by: Knut Olsen-Solberg | last post by:
I try to change the text in a <p> using getElementById(). I wonder what properties exists, and which one to use here. (The following does not work.) Regards Knut ______________________ ...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
13
by: problem. | last post by:
#include <stdio.h> #include <stdlib.h> int main(void) { int a, b; float result = 0.0f; char symbol = '\0'; int loop = 0;
7
by: Tony Johansson | last post by:
Hello! Why does not this cause a compile error because a ulong has never been implicitly convertible to byte? ulong vektor = {100000,200000,300000}; foreach(byte b in vektor) {...
32
by: alex.j.k2 | last post by:
Hello all, I have "PRECISION" defined in the preprocessor code and it could be int, float or double, but I do not know in the code what it is. Now if I want to assign zero to a "PRECISION"...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.