Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<unistd.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6.  
  7. void ft_grep(char path[], char number[]);
  8.  
  9.  
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13. ft_grep("numbers.dict", "1000");
  14.  
  15. }
  16.  
  17. void ft_grep(char path[], char number[])
  18. {
  19. int digits;
  20. int i;
  21. int fd;
  22. char c;
  23. char buf[16];
  24. digits = 4;
  25.  
  26. fd = open(path,O_RDONLY);
  27.  
  28. i = 0;
  29.  
  30. while( i < digits )
  31. {
  32. read(fd, &c, 1);
  33. if ( c == number[i])
  34. i++;
  35. else
  36. i = 0;
  37.  
  38. }
  39. read(fd, &c, 1);
  40. read(fd, &c, 1);
  41. read(fd, &c, 1);
  42. i = 0;
  43. while (c != '\n')
  44. {
  45. buf[i] = c;
  46. read(fd, &c,1);
  47. i++;
  48. }
  49. buf[i] = '\0';
  50. printf("Valor de %s =%s\n", number, buf);
  51. close(fd);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement