First of all, I know there is a question with an identical name, however it deals with c++ and not c.
Is there any way to set a string to the clipboard in c?
This is the mentioned question if anyone is curious, even though it is for windows.
I need it to be in c because I am writing a program in c, and I would like to copy a string to the clipboard.
printf("Welcome! Please enter a sentence to begin.\n> ");
fgets(sentence, ARR_MAX, stdin);
//scan in sentence
int i;
char command[ARR_MAX + 25] = {0};
strncat(command, "echo '",6);
strncat(command, sentence, strlen(sentence));
strncat(command, "' | pbcopy",11);
command[ARR_MAX + 24] = '\0';
i = system(command); // Executes echo 'string' | pbcopy
The above code is saving 2 new lines in addition to the string. ARR_MAX is 300.