如何在:!commandVim 中隐藏表单中任何命令的输出。我也不想在运行此命令(如Press ENTER or type command to continue)后从 Vim 收到任何消息。我希望 shell 命令完全在后台运行。
我有两个字符串,string0和string1.string0是类型char *而string1为类型const char *.string1指向是在堆上分配当空间被释放变为无效,但我知道我以后会需要它的内容的数据.
由于以后释放内存,我不能执行以下操作:
string0 = (char *) string1;
Run Code Online (Sandbox Code Playgroud)
由于这两个都是指针,因此一旦释放内存,它们都将变为无效.这就是我尝试这个的原因:
strcpy(string0, string1);
Run Code Online (Sandbox Code Playgroud)
但这会产生错误:Segmentation fault (core dumped).string1即使在释放堆之后,我还能尝试保留其他内容吗?
我写了一个小程序作为例子来复制我遇到的问题.该程序以这种方式接受和操作两行:
' '),后跟一个数字.'\0'到它.这是最小的程序:
#include <stdio.h>
#include <string.h>
void read(char *text)
{
// create and initialize the line holder
int k = 0;
char line[10];
line[0] = '\0';
for (int i = 0;text[i] != '\0';i++)
{
if (text[i] == '\n')
{
// k now points to the character right after the last assigned one, so put 0 in that place
line[k] = '\0';
// initialize data objects that will hold text and …Run Code Online (Sandbox Code Playgroud)