I need an entire string to be one char of another string.
const char *const_string = "FOOBAR";
char *character_string = malloc(1024);
// character_string = const_string[3];
How can I make the last (commented) line work?
I need an entire string to be one char of another string.
const char *const_string = "FOOBAR";
char *character_string = malloc(1024);
// character_string = const_string[3];
How can I make the last (commented) line work?
It seems you mean the following
void do_something(char *str, int idx)
{
str[0] = glob_str[idx];
str[1] = '\0';
}
You can add a check to the function that the index is not outside the string literal pointed to by glob_str
.
Given
char *glob_str = "test test"; // glob_str is literal string and cannot be modified
then
glob_str[0] = val; // modification won't work
You need to change to
char glob_str[] = "test test";
See this question