Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
- void ft_grep(char path[], char number[]);
- int main(int argc, char* argv[])
- {
- ft_grep("numbers.dict", "1000");
- }
- void ft_grep(char path[], char number[])
- {
- int digits;
- int i;
- int fd;
- char c;
- char buf[16];
- digits = 4;
- fd = open(path,O_RDONLY);
- i = 0;
- while( i < digits )
- {
- read(fd, &c, 1);
- if ( c == number[i])
- i++;
- else
- i = 0;
- }
- read(fd, &c, 1);
- read(fd, &c, 1);
- read(fd, &c, 1);
- i = 0;
- while (c != '\n')
- {
- buf[i] = c;
- read(fd, &c,1);
- i++;
- }
- buf[i] = '\0';
- printf("Valor de %s =%s\n", number, buf);
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement