I have a string "prompt" that holds a string of characters. The user must be able to change the prompt with user input, which I've collected and separated (using whitespace as a delimiter) into an array of char
strings (tokens).
For example, assume:
char **tokens[2] = {"setprompt", "newprompt"};
char *prompt = "oldprompt";
if(strcmp(tokens[0], "setprompt") == 0)
{
strcpy(prompt, tokens[1]);
}
The strcmp()
function works perfectly fine, however when it reaches strcpy()
, the element in tokens[1]
(which is the string "newprompt"
) isn't copied into the string prompt. This is my problem.
I've tried troubleshooting, in addition to using strncpy()
instead but I think there's an issue somewhere with my declarations of each variable/pointer. Any assistance or ideas would be great.
Note: in my actual program, the tokens array doesn't have a definitive size of 2. This example is modified for simplicity. Thanks!