Advertisement
Guest User

Vasilis Code

a guest
Mar 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #define length 256
  6.  
  7. //introduce structs used
  8.  
  9. //Name is a string but number of friends and user id are integers.
  10. struct node
  11. {
  12. char name[50];
  13. //int relationships;
  14. int id;
  15. struct sn *next;
  16. };
  17.  
  18.  
  19.  
  20. //head and current user structure
  21. struct node *head = NULL;
  22. struct node *current = NULL;
  23.  
  24. //various variables
  25. int input,username,n2;
  26. int num = 1;
  27.  
  28. //introduce functions to be used
  29. void new2(int n2);
  30. //void relationship(int n);
  31. void printlist(struct node *n);
  32.  
  33.  
  34. int main ()
  35. {
  36.  
  37.  
  38. //do loop with condition for exit. We always need the menu to appear initially
  39. do
  40. {
  41. //user input menu
  42. printf ("Select an action:\n");
  43. printf ("1.Introduce new user\n");
  44. printf ("2.Introduce social relationship\n");
  45. printf ("3.Print report of all users\n");
  46. printf ("4.Exit\n");
  47. scanf ("%d", &input);
  48. switch (input){
  49. case 1:
  50. new2(num);
  51. num++;
  52. break;
  53. //case 2:
  54.  
  55. //break;
  56.  
  57. case 3:
  58. printlist(head);
  59. break;
  60. case 4:
  61. printf("bye");
  62. break;
  63. default:
  64. printf("error");
  65. break;
  66. }
  67. }while(input<4);
  68.  
  69.  
  70. //Input is number of users
  71. void new2(int n2){
  72. printf("Insert name: ");
  73. scanf("%s",username);
  74. //create a ptr
  75. struct node *ptr = (struct node*) malloc(sizeof(struct node));
  76.  
  77. strcpy(ptr->name,username);
  78. ptr->id = num;
  79.  
  80. //point it to old first node
  81. ptr->next = head;
  82.  
  83. //point first to new first node
  84. head = ptr;
  85. }
  86. //function to introduce new friend
  87. //void relationship(int num){
  88.  
  89. }
  90. //function to print all users
  91. void printlist(struct node *n)
  92. {
  93. while (n != NULL)
  94. {
  95. printf(" %s \n", n->name);
  96. printf(" %d \n",n->id);
  97. n = n->next;
  98. }
  99. }
  100.  
  101.  
  102.  
  103.  
  104. Error:
  105. main.c: In function ‘new2’:
  106. main.c:73:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
  107. scanf("%s",username);
  108. ^
  109. main.c:77:21: warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
  110. strcpy(ptr->name,username);
  111. ^
  112. In file included from main.c:2:0:
  113. /usr/include/string.h:129:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
  114. extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
  115. ^
  116. main.c:81:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  117. ptr->next = head;
  118. ^
  119. main.c: In function ‘printlist’:
  120. main.c:97:8: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  121. n = n->next;
  122. ^
  123. /var/tmp/ccDeZBQG.o: In function `main':
  124. main.c:(.text+0x6c): undefined reference to `new2'
  125. collect2: error: ld returned 1 exit status
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement