CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 2nd March 2008, 10:39 PM
CE - Apprentice
 
I'm a Crazy Computer Science Engineer
Join Date: 2nd March 2008
Posts: 18
Default C problem: What does void strcpy(char *buffer, char const *string) mean?

what does this statement mean??
void strcpy(char *buffer, char const *string)
pallavi agarwal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 2nd March 2008, 11:52 PM
CE - Addict
 
friendster7's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 4th February 2008
Location: india,karnataka
Posts: 386
Send a message via Yahoo to friendster7
Default Re: C problem: What does void strcpy(char *buffer, char const *string) mean?

char strcpy(char *, const char *); copies a string from one location to another
__________________
Vinay Is Cool..

ha ha ha
friendster7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 2nd March 2008, 11:53 PM
CE - Addict
 
friendster7's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 4th February 2008
Location: india,karnataka
Posts: 386
Send a message via Yahoo to friendster7
Default Re: C problem: What does void strcpy(char *buffer, char const *string) mean?

let us say

char *s1; points to an area of memory that is to receive the copied characters. const char *s2; points to the string from which characters will be copied. This must end with the usual '\0'.
__________________
Vinay Is Cool..

ha ha ha
friendster7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 3rd March 2008, 11:13 AM
CE - Apprentice
 
pradeep_agrawal's Avatar
 
I'm a Crazy Computer Engineer
Join Date: 4th May 2006
Posts: 48
Default Re: C problem: What does void strcpy(char *buffer, char const *string) mean?

The prototype is: void strcpy(char *buffer, char const *string);

The function copies the string pointed by variable 'string' to variable 'buffer', i.e., it copies each character starting from the memory location pointed by variable 'string' to to the memory location starting from the one pointed by variable 'buffer'. The function copies the characters till it encounter character '/0' (character having ASCII value 0, represents end of string).

The use of const in 'char const *string' means that variable 'string' is pointer to constant characters, so you can't modify the string represented by variable 'string'.

-Pradeep
pradeep_agrawal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 3rd March 2008, 12:55 PM
CE - Apprentice
 
pradeep_agrawal's Avatar
 
I'm a Crazy Computer Engineer
Join Date: 4th May 2006
Posts: 48
Default Re: C problem: What does void strcpy(char *buffer, char const *string) mean?

But its better to use errno_t strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource); instead of strcpy.

Consider case that your destination buffer is of size 128 and source string has length greater then 128. In such case the code will cause crash.

In strcpy_s, 'size_t numberOfElements' specifies the size of destination string buffer and it returns 0 if copy is successful otherwise returns the error code.

-Pradeep
pradeep_agrawal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



All times are GMT +5.5. The time now is 05:08 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger