I'm trying to copy a const char* string
to a char array[?]
is there a way in C to set my array size automatically? char word[255];
instead of using 255
my program will automatically use the correct size in my case 10. If there's a better way to do it I'm open to any suggestions thx a lot.
const char* test_str = "my string.";
int lenght = strlen(test_str), x=0;
char word[255] = {'\0'};
//memset(word, '\0', sizeof(word));
while (x < lenght) {
word[x] = test_str[x];
x++;
}
printf("%s", word);
edit: Removed memset(word, '\0', sizeof(word));
and replaced with word[255]= {'\0'};