fork download
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3.  
  4. struct queue
  5. {
  6. int data;
  7. struct queue *next;
  8. };
  9.  
  10. queue* enqueue(queue *head, queue **tail, int num);
  11.  
  12. int main()
  13. {
  14. int i;
  15. queue *head1=NULL; //目前只宣告第一個queue 之後想再多加幾個
  16. queue *tail1=NULL; //可能會命名為head2....
  17. queue *current=NULL;
  18.  
  19. for(i=0; i<10; i++)
  20. {
  21. head1 = enqueue(head1, &tail1, i);
  22. current = head1;
  23.  
  24. while(current != NULL)
  25. {
  26. printf("%d ", current->data);
  27. current = current->next;
  28. }
  29. printf("\n");
  30. }
  31.  
  32. system("pause");
  33. return 0;
  34. }
  35.  
  36. queue *enqueue(queue *head, queue **tail, int num)
  37. {
  38. queue *newnode;
  39. newnode = (queue*)malloc(sizeof(queue));
  40. (*newnode).data = num;
  41.  
  42. newnode->next = NULL;
  43.  
  44. if(*tail == NULL)
  45. head = newnode;
  46. else
  47. (*tail)->next = newnode;
  48.  
  49. *tail = newnode;
  50.  
  51. return head;
  52. }
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
prog.c: In function ‘main’:
prog.c:15: error: ‘queue’ undeclared (first use in this function)
prog.c:15: error: (Each undeclared identifier is reported only once
prog.c:15: error: for each function it appears in.)
prog.c:15: error: ‘head1’ undeclared (first use in this function)
prog.c:16: error: ‘tail1’ undeclared (first use in this function)
prog.c:17: error: ‘current’ undeclared (first use in this function)
prog.c:21: warning: implicit declaration of function ‘enqueue’
prog.c:32: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
prog.c: At top level:
prog.c:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
stdout
Standard output is empty