C - 如何保持变量
C - how to keep variable
我想知道如何将文本保存在 txt 变量中?我想保留它直到我的函数结束——我认为它叫做 static int
#include <stdio.h>
#include <stdlib.h>
int main()
{
char buf[1024];
char txt[100];
printf("Insert a text: ");
fgets(txt, 100, stdin);
snprintf(buf, sizeof(buf), "echo '%s'", txt);
system(buf);
}
谢谢,
马特
您得到的错误与buf
的范围无关。
它指的是 system
函数,它只需要一个参数:
int system(const char *command)
希望我有所帮助。
我想知道如何将文本保存在 txt 变量中?我想保留它直到我的函数结束——我认为它叫做 static int
#include <stdio.h>
#include <stdlib.h>
int main()
{
char buf[1024];
char txt[100];
printf("Insert a text: ");
fgets(txt, 100, stdin);
snprintf(buf, sizeof(buf), "echo '%s'", txt);
system(buf);
}
谢谢, 马特
您得到的错误与buf
的范围无关。
它指的是 system
函数,它只需要一个参数:
int system(const char *command)
希望我有所帮助。