1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include <stdio.h>
#include <string.h>
#define TAILLE_MAX 1024
void copyfiletobuffer ( char *file, char *buffer)
{
FILE *file_open;
file_open = fopen (file, "r");
if (file_open != NULL )
{
while (fgets (buffer, TAILLE_MAX, file_open) != NULL)
{
//printf ("%s\n", buffer);
}
fclose (file_open);
}
else
printf ("\n erreur lors de l'ouverture du fichier \n");
}
void copybuffertotemp (char *buffer, char temp[TAILLE_MAX][TAILLE_MAX])
{
int i = 0;
int u = 0;
int j = 0;
while ( buffer[i] != '\0')
{
while (buffer[i] != '\n')
{
temp[u][j] = buffer[i];
i++;
u++;
}
temp[u][j] = '\0' ;
i++;
j++;
}
temp[u][j] = '\0' ;
for (u=0; u<TAILLE_MAX; u++)
printf ("%s\n", temp);
}
int main (int ac, char **av)
{
char buffer[TAILLE_MAX];
char temp[TAILLE_MAX][TAILLE_MAX];
copyfiletobuffer(av[1], buffer);
copybuffertotemp (buffer, temp);
return 0;
} |
Partager