Connecting Tech Pros Worldwide Help | Site Map

copying chars in TC++

  #1  
Old December 7th, 2006, 04:35 AM
MC felon
Guest
 
Posts: n/a
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++)

  #2  
Old December 7th, 2006, 05:15 AM
raymondhuanghz@gmail.com
Guest
 
Posts: n/a

re: copying chars in TC++


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

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

"MC felon дµÀ£º
"
Quote:
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++)
  #3  
Old December 7th, 2006, 05:15 AM
John Carson
Guest
 
Posts: n/a

re: copying chars in TC++


"MC felon" <paec.nwa@gmail.comwrote in message
news:1165467429.523461.295150@16g2000cwy.googlegro ups.com
Quote:
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.
Quote:
return 0;
}
>
>
any help on this is really appreciated! (please note that i work on
TC++)

--
John Carson


  #4  
Old December 7th, 2006, 05:55 AM
MC felon
Guest
 
Posts: n/a

re: copying chars in TC++


thank you all a lot for sparing your time!

  #5  
Old December 8th, 2006, 09:15 PM
Aston Martin
Guest
 
Posts: n/a

re: copying chars in TC++


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]

On Dec 6, 11:57 pm, "MC felon" <paec....@gmail.comwrote:
Quote:
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++)
Closed Thread