copying chars in TC++

M

MC felon

hello.
this is a very new-B question. But how do i copy one char in a string
to a char place in another string?
i tried this, but it signalled errors.

#include <whateverisrequired.h>

int main()
{
char out[100];
char str[100];
gets(str);
strcpy(out[1],str[5]);
return 0;
}


any help on this is really appreciated! (please note that i work on
TC++)
 
J

John Carson

MC felon said:
hello.
this is a very new-B question. But how do i copy one char in a string
to a char place in another string?
i tried this, but it signalled errors.

#include <whateverisrequired.h>

int main()
{
char out[100];
char str[100];
gets(str);
strcpy(out[1],str[5]);

out[1] = str[5];

strcpy works on null-terminated strings, not on single characters.
 
R

raymondhuanghz

A simple assignment would do that:
str[5] = out[1];

ps: out is not properly initialized, it may contain garbage in it

"MC felon дµÀ£º
"
 
A

Aston Martin

out[1] is equal to *(out+1) and what function expects is char*
perhaps u want this
strcpy( out + 1, str + 5 );
be sure to initialize out[0]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top