Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. Publication get_publication(char* command)
  2. {
  3.    char *authorsStr = NULL, *idsStr = NULL;
  4.    Publication p = malloc(sizeof(Publication));
  5.    List author = NULL, bibliography = NULL;
  6.  
  7.    if(p == NULL)
  8.    {
  9.       printf("Allocation error\n");
  10.       exit(-1);
  11.    }
  12.  
  13.    command += 2;
  14.  
  15.    p->position = position_from_str_to_int(trim(strtok(command, "|")));
  16.    p->id = trim(strtok(NULL, "|"));
  17.    p->title = trim(strtok(NULL, "|"));
  18.  
  19.    authorsStr = strtok(NULL, "|");
  20.    idsStr = strtok(NULL, "|");
  21.  
  22.    authorsStr = strtok(authorsStr, "&");
  23.  
  24.    while(authorsStr != NULL)
  25.    {
  26.       authorsStr = trim(authorsStr);
  27.       author = add_to_list(author, authorsStr);
  28.       authorsStr = strtok(NULL, "&");
  29.    }
  30.  
  31.    idsStr = strtok(idsStr, "&");
  32.  
  33.    while(idsStr != NULL)
  34.    {
  35.       idsStr = trim(idsStr);
  36.       bibliography = add_to_list(bibliography, idsStr);
  37.       idsStr = strtok(NULL, "&");
  38.    }
  39.  
  40.    p->authors = author;
  41.    p->bibliography = bibliography;
  42.  
  43.    printf("%d\n", p->position);
  44.    printf("%s\n", p->id);
  45.    printf("%s\n", p->title);
  46.  
  47.    printf("%s\n", p->authors->value);
  48.    printf("%s\n", p->authors->next->value);
  49.  
  50.    printf("%s\n", p->bibliography->value);
  51.    printf("%s\n", p->bibliography->next->value);
  52.  
  53.    return p;
  54. }
Add Comment
Please, Sign In to add comment