473,324 Members | 2,179 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,324 software developers and data experts.

Error on strcat

Hi,

I have this problem:

int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];

/* HERE MAIN WITH THE INPUT OF n*/

itoa(n, nToChar, 10);
resp = strcat(firstString, nToChar);

/* END */

When I compile, this error is returned: incompatible type in
assignment (strcat)

How can resolve the problem ? I hope in Your help.
Best Regards
Gaetano

Apr 9 '07 #1
4 4683
"nick048" <ni*************@moonsoft.itwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Hi,

I have this problem:

int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];

/* HERE MAIN WITH THE INPUT OF n*/

itoa(n, nToChar, 10);
resp = strcat(firstString, nToChar);
strcat returns a char pointer that points to, in your case, firstString.

Now, you are trying to assign resp, which is a character array, a pointer
value.

I think you are trying to use strcat wrong. strcat will copy the contents
of the second string to the end of the first string, modifying the first
string. Which means you have problems with your code.

firstString only contains enough chars for "The number is: " which is 16
counting the null terminator. You are trying to add the string "5" to it,
but don't have enough room. What you probably want is:

strcpy( resp, firstString );
strcat( resp, nToChar );
>
/* END */

When I compile, this error is returned: incompatible type in
assignment (strcat)

How can resolve the problem ? I hope in Your help.
Best Regards
Gaetano

Apr 9 '07 #2

Jim Langston је написао
"nick048" <ni*************@moonsoft.itwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Hi,

I have this problem:

int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];

/* HERE MAIN WITH THE INPUT OF n*/

itoa(n, nToChar, 10);
resp = strcat(firstString, nToChar);

strcat returns a char pointer that points to, in your case, firstString.

Now, you are trying to assign resp, which is a character array, a pointer
value.

I think you are trying to use strcat wrong. strcat will copy the contents
of the second string to the end of the first string, modifying the first
string. Which means you have problems with your code.

firstString only contains enough chars for "The number is: " which is 16
counting the null terminator. You are trying to add the string "5" to it,
but don't have enough room. What you probably want is:

strcpy( resp, firstString );
strcat( resp, nToChar );

/* END */

When I compile, this error is returned: incompatible type in
assignment (strcat)

How can resolve the problem ? I hope in Your help.
Best Regards
Gaetano

Try using this trick;
int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];

/* HERE MAIN WITH THE INPUT OF n*/

itoa(n, nToChar, 10);
char* point;
point = &nToChar;
resp = strcat(firstString, point);
It might help;

Apr 9 '07 #3
SambucusELF wrote:
\
>
Try using this trick;
>>int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];

/* HERE MAIN WITH THE INPUT OF n*/

itoa(n, nToChar, 10);
char* point;
point = &nToChar;
>>resp = strcat(firstString, point);

It might help;
It won't help, it causes more compiler errors than his
original code. Programming is not just poking at code
with a stick hoping for the best.

Further there's no such function itoa.

Frankly, this is C++ after all. If you're not adept
with managing memory allocations and null-terminated
character arrays (char* and char[] are in fact NOT
string types at all).

The above would have sorked better:

std::ostringstream fresp;
fresp << "The number is: " << n;

std::string resp = fresp.str();

Apr 9 '07 #4
On Apr 9, 10:59 am, "nick048" <nicosia.gaet...@moonsoft.itwrote:
I have this problem:
Rather:-).
int n;
char nToChar[5];
char firstString[ ] = "The number is: ";
char resp[40];
/* HERE MAIN WITH THE INPUT OF n*/
itoa(n, nToChar, 10);
resp = strcat(firstString, nToChar);
/* END */
When I compile, this error is returned: incompatible type in
assignment (strcat)
How can resolve the problem ?
The most obvious way:

std::ostringstream tmp ;
tmp << "The number is: " << n ;
std::string resp = tmp.str() ;

Why make things harder than they are?

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique oriente objet/
Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

Apr 10 '07 #5

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

Similar topics

7
by: mattsniderppl | last post by:
Hi, i'm relatively new to C++ from java and am having a difficult time with pointers. I'm sure there is something simple that I am doing wrong, but I can't seem to write this in a way that doesn't...
2
by: ritchie | last post by:
Hi, Just wanted to ask if anybody has any idea what i'm doing wrong. I have a function which edits a linked list. It works fine. I pass in a pointer to the list plus the value of the item to...
2
by: Juan Jose Costello Levien | last post by:
Hello, I am trying to use a trigger function I wrote in C. Basically what I want to do is to audit a table when a row is inserted into another table by copying the row to the new table. It...
8
by: ctara_shafa | last post by:
Hi, I have a following problem: I'm creating a list and one of the fields should contain the date. Firstly I ask the user for the year, month and day and then I'd like to collect all this data in...
6
by: santosh | last post by:
The following code is giving run-time error..... char buf = "Hello" ; strcat(buf,buf) ; Second line is giving the run-time error. Any comments please............
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
5
by: RomeoPapacy | last post by:
I'm trying to write what should be a very simple program - a system tray based menu to allow me to quickly access files in a folder (for me a bunch of disc images). Unfotunately i'm stumped near...
4
by: MonkeyHater | last post by:
This program is a random sentence generator. I have it running.. more or less. When it complies I will get some correct sentences and I will get some sentences that don't even contain real words....
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.