**WHY StrCpy - dosen't work normally :( ? Where is mistakes?**
#include"string.c"
int main()
{
printf("Hello World!\n");
char *text = "GOOOD TEXT ALL TIME VERY POOR ";
int temp = strlen(text);
char *copy_text;
printf("size text: %d\n", temp);
StrCpy( copy_text, text );
printf("TEXT: %s\n COPY_TEXT %s", text, copy_text );
return 0;
}
//string.c
int StrLen( const char* str )
{
if( str != ZERO )
{
const char* copy_str;
for( copy_str = str; *copy_str; ++copy_str )
{
;/* Discard */
}
return ( copy_str - str );
}
else
{
return ZERO;
}
}
char* StrCpy( char* destination, const char* source )
{
int size_source = StrLen( source );
int size_destination = StrLen( destination ); // !!!! Every time zero
if( size_source )
{
memcpy( destination, source, ( size_source + 1 ) );
return destination;
}
else
{
return ZERO;
}
}
//
Nikolas9896
0
Newbie Poster
Recommended Answers
Jump to PostYou've encountered a common beginner issue. Allow me to point it out more clearly:
// This is a pointer to a string literal. You can't modify it. char *text = "GOOOD TEXT ALL TIME VERY POOR "; // This is an uninitialized pointer, you can't read from …
All 4 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Nikolas9896
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Banfa
597
Posting Pro
Featured Poster
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.