前提・実現したいこと
連結リストの表示関数がうまく動かないです。
発生している問題・エラーメッセージ
リスト表示がされません。
該当のソースコード
C
1 2#include <stdio.h> 3#include <stdlib.h> 4 5struct CELL{ 6 int value; 7 struct CELL *next; 8}; 9 10struct CELL *header1; 11 12/*先頭に追加*/ 13void insert(int n,struct CELL *header) 14{ 15 struct CELL *new; 16 if ((new=malloc(sizeof(struct CELL)))==NULL){ 17 printf("メモリ不足"); 18 exit(1); 19 } 20 new->next=header; 21 new->value=n; 22 header=new; 23 24} 25 26void print_list(struct CELL *header) 27{ 28 struct CELL *p; 29 30 printf("リスト:"); 31 for (p=header;p!=NULL;p=p->next){ 32 printf("%d,",p->value); 33 } 34} 35 36int main(void) 37{ 38 int n; 39 int count=10; 40 while(count){ 41 printf("追加する要素:"); scanf("%d",&n); 42 insert(n,header1); 43 print_list(header1); putchar('\n'); 44 count--; 45 } 46} 47
補足情報(FW/ツールのバージョンなど)
Xcode Version 11.2 (11B52)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/14 13:33