Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #define length 256
- //introduce structs used
- //Name is a string but number of friends and user id are integers.
- struct node
- {
- char name[50];
- //int relationships;
- int id;
- struct sn *next;
- };
- //head and current user structure
- struct node *head = NULL;
- struct node *current = NULL;
- //various variables
- int input,username,n2;
- int num = 1;
- //introduce functions to be used
- void new2(int n2);
- //void relationship(int n);
- void printlist(struct node *n);
- int main ()
- {
- //do loop with condition for exit. We always need the menu to appear initially
- do
- {
- //user input menu
- printf ("Select an action:\n");
- printf ("1.Introduce new user\n");
- printf ("2.Introduce social relationship\n");
- printf ("3.Print report of all users\n");
- printf ("4.Exit\n");
- scanf ("%d", &input);
- switch (input){
- case 1:
- new2(num);
- num++;
- break;
- //case 2:
- //break;
- case 3:
- printlist(head);
- break;
- case 4:
- printf("bye");
- break;
- default:
- printf("error");
- break;
- }
- }while(input<4);
- //Input is number of users
- void new2(int n2){
- printf("Insert name: ");
- scanf("%s",username);
- //create a ptr
- struct node *ptr = (struct node*) malloc(sizeof(struct node));
- strcpy(ptr->name,username);
- ptr->id = num;
- //point it to old first node
- ptr->next = head;
- //point first to new first node
- head = ptr;
- }
- //function to introduce new friend
- //void relationship(int num){
- }
- //function to print all users
- void printlist(struct node *n)
- {
- while (n != NULL)
- {
- printf(" %s \n", n->name);
- printf(" %d \n",n->id);
- n = n->next;
- }
- }
- Error:
- main.c: In function ‘new2’:
- main.c:73:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
- scanf("%s",username);
- ^
- main.c:77:21: warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
- strcpy(ptr->name,username);
- ^
- In file included from main.c:2:0:
- /usr/include/string.h:129:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
- ^
- main.c:81:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
- ptr->next = head;
- ^
- main.c: In function ‘printlist’:
- main.c:97:8: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
- n = n->next;
- ^
- /var/tmp/ccDeZBQG.o: In function `main':
- main.c:(.text+0x6c): undefined reference to `new2'
- collect2: error: ld returned 1 exit status
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement