Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include "mpasswdsort.h"
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. void parse(FILE *stream, llist list)
  8. {
  9.     char *ret, buff[MAX_BUFF_SIZE];
  10.  
  11.     while ((ret = fgets(buff, MAX_BUFF_SIZE, stream))) {
  12.         if (ferror(stream) || !ret) {
  13.             fprintf(stderr, strerror(errno));
  14.         }
  15.  
  16.         char *s = buff;
  17.  
  18.         /*
  19.          * username:password:UID:GID:GECOS:directory:shell
  20.          * 1-32    :        :>1 : >1
  21.          */
  22.  
  23.         printf("%s", s);
  24.         for (int i = 0; i < 6; i++) {
  25.             char *sep = strchr(s, ':');
  26.             *sep = '\0';
  27.             char name[1024];
  28.             strcpy(name, s);
  29.             printf("%s\n", name);
  30.  
  31.             s = sep + 1;
  32.         }
  33.         printf("%s", s);
  34.  
  35.     }
  36.  
  37.     list = list;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement