2015-05-09 92 views
-2

我想知道我怎么能保持在TXT变量的文本?我想保持它unitl我的功能将结束 - 我想,这就是所谓的静态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); 
} 

谢谢, 马特

+2

'txt'将被保留,直到其范围结束。你能澄清你的问题吗?上述代码的问题究竟是什么? – Mureinik

+0

“*我想保持它unitl我的功能将结束*”它已经这样做 –

+0

如果选中它是静态的,它会被保留,直到你的* *程序结束。这是你问的吗? –

回答

1

你拿到了无关的buf范围的误差。 它是指system功能,预计只有一个参数:

int system(const char *command) 

希望我帮助。