Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with strcpy() and arrays

Status
Not open for further replies.

GregV1

Programmer
Aug 12, 2009
1
0
0
NL
I am using Borland Builder 5. I have a problem with variables. I have a char array of length nine. I only use characters '0' '1' and '2'.
When I use strcpy() sometimes it puts a '\' character somewhere in the string. Also when I dont use stringcopy it still does the same thing (altering the values of the array).
How is this possible?

Thank you.
 
Which project do you use in C++Builder. Console? Are you writing C? Maybe the '\' comes from the null terminating Character '\0'. It is the reason why you should declare a character array one character longer than the largest string that it is to hold.
And a for loop will look like:
for(int i=0; string !='\0'; i++)
 
Be aware between the difference of 'a' and "a".
when you use strcpy(s1,"a") instead of strcpy(s1,'a') a null char '\0' will added.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top