C - 如何保持变量

时间:2015-05-09 14:29:28

标签: c static int

我想知道如何将文本保存在txt变量中?我想保持它单元我的功能将结束 - 我认为它被称为静态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);
}

谢谢, 马特

1 个答案:

答案 0 :(得分:1)

您获得的错误与buf的范围无关。 它引用system函数,它只需要一个参数:

int system(const char *command)

希望我帮助过。