Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** bsq_part_one.c
- ** undefined
- ** File description:
- ** bsq_part_one.c
- */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "bsq.h"
- char **malloc_double_table(char *buff, int size);
- int fs_open_file(char const *file_path)
- {
- int open_file = 0;
- open_file = open(file_path, O_RDONLY);
- if (open_file < 0)
- my_putstr("ECHEC");
- else {
- my_putstr("SUCCESS");
- my_putchar('\n');
- read_file(file_path, open_file);
- }
- return (0);
- }
- int read_file(char const *file_path, int open_file)
- {
- struct stat file_stat;
- long int size = 0;
- char *buff;
- stat(file_path, &file_stat);
- size = file_stat.st_size;
- buff = malloc(sizeof(char) * (size + 1));
- read(open_file, buff, size);
- buff[size] = '\0';
- //my_putstr(buff);
- malloc_double_table(buff, size);
- return (0);
- }
- int cordoner_y(char *tab)
- {
- int y = 0;
- for (int i = 0; tab[i]; i++) {
- if (tab[i] == '\n')
- y++;
- }
- return (y);
- }
- int cordoner_x(char *tab)
- {
- int i = 0;
- // INTERPOLATION
- for (i; tab[i] != '\n'; i++)
- i++;
- return (i);
- }
- char *my_strcpy(char *dest, char const *src)
- {
- int y = 0;
- int x = 0;
- for (int i = 0; src[i] != '\0'; i++) {
- if (src[i] == '\n' && y == 0) {
- y++;
- }
- else if (y >= 1) {
- dest[x] = src[i];
- x++;
- }
- }
- dest[x] = '\0';
- return (dest);
- }
- char **complet_double_tab(char **double_table, char *table)
- {
- int y = 0;
- int x = 0;
- for (int i = 0; table[i] != '\0'; i++) {
- if (table[i] == '\n') {
- x = 0;
- y++;
- }
- else {
- double_table[y][x] = table[i];
- x++;
- }
- }
- return (double_table);
- }
- char **malloc_double_table(char *buff, int size)
- {
- char *new_tab = malloc(sizeof(char) * (size + 1));
- new_tab = my_strcpy(new_tab,buff);
- int x = cordoner_x(new_tab); // nombre de ligne = 33 caracte x = 34 + 1
- int y = cordoner_y(new_tab); // nombre de cologne y = 9 + 2x
- char **double_table = malloc(sizeof(char*) * (y + 2));
- for (int i = 0; i <= y + 1; i++)
- double_table[i] = malloc(sizeof(char) * (x + 1));
- double_table[y + 1] = NULL;
- double_table = complet_double_tab(double_table,new_tab); // completer le premier tableau. en char
- copy_double_tab_bi(double_table, x, y); // paas besoin ppour créeer le double tab en int avec les valeurs inisilation
- }
- int main(int argc, char const *argv[])
- {
- fs_open_file(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement