what is the actual use of strcpy

0 digvijay Jadeja · July 29, 2015
according  to the  tutorials we actually us that commond 
strcpy 
for the purpose of changing the value assigned in the array .
Like in the tutorial we changed the array food its string value .
So is that wat it is strcpy to change the value of array.
 
and one more thing i get the warning while ruuning the commond with strcpy



#include
#include

int main()
{
  char name[16] = "Digvijay Jadeja";
   printf("My name is %s \n", name);

   name[2] = 'z';

   printf("my name is %s \n ", name);

     strcpy(name, "Digivijay");

    printf("my name is %s \n", name);

    return 0;
}


||=== Build: Debug in dj (compiler: GNU GCC Compiler) ===|
C:\Users\Digvijay52\Desktop\dj\main.c||In function 'main':|
C:\Users\Digvijay52\Desktop\dj\main.c|13|warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]|
C:\Users\Digvijay52\Desktop\dj\main.c|13|warning: incompatible implicit declaration of built-in function 'strcpy' [enabled by default]|
||=== Build finished: 0 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
||=== Run: Debug in dj (compiler: GNU GCC Compiler) ===|

Post a Reply

Replies

Oldest  Newest  Rating
0 Steven the awesome · July 29, 2015
Well actually you are not changing the value of the array, you copy the string and print it out again. 

And by the way I don't get an error.
0 Steven the awesome · July 29, 2015
http://www.tutorialspoint.com/c_standard_library/c_function_strcpy.htm
0 c student · July 30, 2015
NO. NO. NO. NO. i'd HIGHLY recommend you don't use any string/array functions until you actually know what you're doing.

"A Buffer Overflow is a flaw that occurs when more data is written to a block of memory, or buffer, than the buffer is allocated to hold."

http://projects.webappsec.org/w/page/13246916/Buffer%20Overflow
  • 1

C

107,182 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator