Hi.. I am learning C using Def c++. I struck at strcpy command. It giving error for a small exercise

#include<stdio.h>
main()
{
      char string[20];
      
      strcpy("Hello", string); 
      
      printf("%s", string);
      fflush(stdin);
      getchar();
      }

it giving error:
`strcpy' undeclared (first use this function)

Please help me that what can i do in dev c++ to get rid of this problem

Recommended Answers

All 10 Replies

you also need to include string.h header file, like you did stdio.h header file.

>>what can i do in dev c++
First, stop using that old, obsolete compiler. Download free Code::Blocks with MinGW (they are free).

Reread how strcpy() statement is formed.

Also, see this.

As waltp said reread the syntax of strcpy(). It should be like this.

strcpy(string,"HELLO");

strcpy( /*character array which will hold the text after copying */ , /*string that is to be copied into another array*/ ) ;

commented: I could have told him that -- I wanted him to look it up -4
commented: Stop downvoting people WaltP! You are so mean. He was just trying to help! +0

i think hidder files are missing
include the sdtlib.h file.
might work.

commented: Do not post if you have no idea what you're talking about! -4

Thanks guys..
Thank your very much.....
specially for ancient dragon for solving my problem

i think hidder files are missing
include the sdtlib.h file.
might work.

No it won't. strcpy() is declared in string.h

add string.h library

add string.h library

I don't know how many times this has to be said. BTW string.h is NOT a library!

I can't believe nobody mentioned that you need to include string.h. :icon_rolleyes:

:D

Narue -- your avatar is quite appropriate to that comment :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.