2015-05-09 94 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) 

希望我幫助。