#define HISTORY_SIZE 50
#define INPUT_SIZE 512 /*Max input size*/
char input[INPUT_SIZE]; /*Holding user input globaly*/
char* input_history[HISTORY_SIZE];
これは、入力にして、私の入力を保存し、そのコピーを保存したいイムでinput_historyする方法ですC:、ユーザー入力を取得、保存、continueingその後、表示の最後の50個の入力
void addToHistory()
{
/*input_history[currentHistorySize++] = strtok(input,"\n");*/
input_history[currentHistorySize++] = input;
printf("ADDEDTOHISTORY: %s \t\t %d \n", input_history[(currentHistorySize- 1)],currentHistorySize);
}
しかし、私はそれをプリントアウトするために行くとき、それは
/*strcpy(input,input_history[currentHistorySize-2]);
printf("LAST INPUT, %s \n %s \n \n", input,input_history[currentHistorySize-2]);*/
printf("0: %s \n ", input_history[0]);
printf("1: %s \n ", input_history[1]);
printf("2: %s \n ", input_history[2]);
アイブ氏は、年齢のためにこれをうまくしようとして座ってとカントは、イムが間違って行く場所を確認するように見える、多分新しい目のペアがわかります....仕事doesntのいくつかの愚かな間違い?
私は
fgets(input,INPUT_SIZE,stdin)
を使用して、ユーザーの入力をしたいBasiclyは、その後のchar *のinput_history にそれのコピーを保存し、後でそれをプリントアウトすることができます。
非常に単純です。代わりにinput_history
が初期化されると仮定すると
input_history[currentHistorySize++] = input;
使用
sprintf(input_history[currentHistorySize++],"%s",input);
の
「動作しません」と定義します。 – cnicutar