Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 7th, 2006, 04:35 AM
MC felon
Guest
 
Posts: n/a
Default copying chars in TC++

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
Default 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
Default 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
Default 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
Default 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++)
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles