首先,我知道有一个问题具有相同的名称,但它处理C++而不是c。将字符串复制到剪贴板c
有没有什么办法可以将字符串设置为c中的剪贴板?
This is the mentioned question if anyone is curious, even though it is for windows.
我需要它在C,因为我用C写一个程序,我想一个字符串复制到剪贴板。
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
上面的代码除了字符串以外还保存了2个新行。 ARR_MAX是300.
您链接到的问题是为Windows。你已经为OS X标记了你的问题。当然,这些完全不同。请澄清你的问题。另外,你能解释一下为什么**使用C语言很重要? – 2014-11-20 23:34:31
我已经添加了一个简短的功能,它正是你想要的。而不使用strncat,这似乎对我来说很迟钝。 – 2014-11-22 05:19:19
尝试接受一个提示! – 2014-12-02 05:01:19