fork download
  1. #include<stdio.h>
  2. struct node{
  3. char name[20];
  4. int no;
  5. struct node *next;
  6. }*start = NULL;
  7. void add(){
  8. struct node *t, *temp;
  9. t = start;
  10. temp = (struct node *)malloc(sizeof(struct node));
  11. printf("\nEnter the customer's name: ");
  12. gets(temp->name);
  13. printf("\nEnter the phone number: ");
  14. scanf("%d", &temp->no);
  15. if(start == NULL){
  16. start = temp;
  17. start->next = NULL;
  18. }
  19. else{
  20. while(t->next!=NULL)
  21. t = t->next;
  22. t->next = temp;
  23. t = temp;
  24. t->next = NULL;
  25. return;
  26. }
  27. void display(){
  28. struct node *temp;
  29. temp = start;
  30. if(temp == NULL){
  31. printf("\nList empty.");
  32. return;
  33. }
  34. while(temp!=NULL){
  35. printf("\nInfo: Cust. name: %s\tCust. phone: %d", temp->name, temp->no);
  36. temp = temp->next;
  37. }
  38. }
  39. void main(){
  40. int n;
  41. n=1;
  42. while(n){
  43. add();
  44. display();
  45. scanf("%d", &n);
  46. }
  47. return;
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void add()’:
prog.cpp:10: error: ‘malloc’ was not declared in this scope
prog.cpp:27: error: a function-definition is not allowed here before ‘{’ token
prog.cpp:48: error: expected `}' at end of input
prog.cpp:12: warning: ignoring return value of ‘char* gets(char*)’, declared with attribute warn_unused_result
prog.cpp:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
Standard output is empty