72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/04/01 07:11:58 by tischmid #+# #+# */
|
|
/* Updated: 2023/04/01 18:19:25 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "main.h"
|
|
#include "ft_strlib.h"
|
|
#include "argparse.h"
|
|
#include "ft_linked_list.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "ft_io.h"
|
|
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
/* read `size' bytes from file `path' beginning at `offset', storing
|
|
* all chars in `buf', where `buf' is terminated at the first newline
|
|
* found. On success, returns number of characters found, -1 on error
|
|
* or EOF with 0 chars read.
|
|
*/
|
|
int readline(/*char *buf, unsigned int size, */ char *path/*, int offset*/)
|
|
{
|
|
int counter;
|
|
int fd;
|
|
char c;
|
|
|
|
fd = open(path, O_RDONLY);
|
|
if (fd < 0)
|
|
return (-1);
|
|
counter = 0;
|
|
while (read(fd, &c, sizeof(c)) > 0)
|
|
if (c == 1)
|
|
++counter;
|
|
close(fd);
|
|
return (counter);
|
|
}
|
|
|
|
int parse_dict(char *path/*, t_map_entry *map*/)
|
|
{
|
|
printf("Number of 1's: %d\n", readline(path));
|
|
|
|
// if (fd < 0)
|
|
// return (0);
|
|
// if (close(fd) < 0)
|
|
// return (1);
|
|
return (1);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char *str_nbr;
|
|
char *path;
|
|
// t_map_entry *map;
|
|
|
|
if (!parse_args(argc, argv, &path, &str_nbr))
|
|
return (puterr("Error\n", 1));
|
|
// if (!parse_dict(path, map))
|
|
// return (puterr("Dict Error\n", 2));
|
|
// ll_clear(map);
|
|
parse_dict(path);
|
|
return (0);
|
|
}
|