標準入力からデータを受け取り最後の3行を表示するプログラムを作成したいです。
そのためまず
3つの循環リストに1行ずつプログラムを代入し回していくプログラムを作ろうと思ったのですが、
fputcの文字を構造体の文字列に追加していきたいのですが、うまくいきません。
C
1#include<stdio.h> 2#include<stdlib.h> 3#include<string.h> 4 5typedef struct test 6{ 7 //int count; 8 char tmpbuf[100]; 9 struct test* next; 10}tests; 11 12 13 14int main(){ 15tests *tmp = NULL; 16tests *head=NULL; 17tests*tail=NULL; 18 19// 20tmp=malloc(sizeof(tests)); 21 22head=tail=tmp; 23tmp->next=malloc(sizeof(tests)); 24 25tmp=tmp->next; 26tmp->next=malloc(sizeof(tests)); 27 28tail=tmp->next; 29tail->next=head; 30 31head=tmp; 32char c; 33int count = 0; 34while ((c=fgetc(stdin)) != EOF){ 35char str=(char)c; 36strcpy(c,tmp->tmpbuf);//ここをcで取得した1文字をtmpbufに追加したい 37if(c=='\n'){tmp=tmp->next; 38} 39 40} 41 42for (int i=0;i<=3;i++){ 43printf("%s",tmp->tmpbuf); 44 45tmp=tmp->next; 46 47} 48 49return 0; 50}
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/18 08:32