I'm trying to copy a even number of char in another string. It does not work at all. But if I try to copy a odd number of char it works. I try to use a for and the function strncpy and it print the word that I want plus a randome letter.
int position=6;
char *stringFirst=malloc(position);
for(int j=0;j<position;j++){
stringFirst[j]=fileStingToMod[j];
}
printf("%s",stringFirst);
free(stringFirst);
This is another code that I try to run:
int position=6;
char *stringFirst=malloc(position);
strncpy(stringFirst,fileStingToMod,position);
printf("%s",stringFirst);
free(stringFirst);
In both cases, the code gives me the following output:
cammelÙ
or
cammel↓
The string, named fileStringToMod
, is : "cammelloverde"
.