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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define TAILLE_MAX 128 // Tableau de taille 128
#define VRAI 1
#define FAUX 0
typedef struct str_fichier{
char *nom ;
FILE* p_fic;
int longueur;
} type_fic, * p_type_fic;
int main(int argc , char * argv[]) {
unsigned char buffer[TAILLE_MAX + 1]; //tabeau avec le 129 /0 pour l'affichage
// FILE* file;
int i, c, nb_blocks, count;
int taille_chaine;
// allocation des deux str_fichier
type_fic fic_lu = {NULL,NULL,0};
type_fic fic_ecr = {NULL,NULL,0};
p_type_fic p_fic_lu = &fic_lu;
p_type_fic p_fic_ecr = &fic_ecr;
if (argc <1) {
if (argc >=2) {
printf("Pas de prise en charge des arguments en exces\n\n");
} else{
taille_chaine= strlen(argv[1]);
p_fic_lu->nom = malloc( taille_chaine * sizeof(char));
memset(p_fic_lu->nom ,0,taille_chaine);
strcpy(p_fic_lu->nom , argv[1]);
}
} else
{
printf("Absence du parametre \n\n");
// valeur par defautdu fichier d'entree en phase de test
// en phase finale sortir du programme
// return EXIT_FAILURE; //fin de traitement
// strcpy(p_fic_lu->nom , "//home//eric//Documents//Exo0001//AM022-203248-20161227145845");
// strcpy(p_fic_lu->nom , "C:\\Users\\moi\\Documents\\Exo0001\\AM022-203248-20161227145845");
taille_chaine = 150;
p_fic_lu->nom = malloc( taille_chaine * sizeof(char));
memset(p_fic_lu->nom ,0,taille_chaine);
strcpy(p_fic_lu->nom , "/home/eric/Documents/Exo0001/AM022-203248-20161227145845");
p_fic_lu->longueur = taille_chaine;
}
printf("Fichier en lecture %s \n\n",p_fic_lu->nom);
// definition du fichier de sortie
taille_chaine= p_fic_lu->longueur + 5;
p_fic_ecr->nom = malloc( taille_chaine * sizeof(char));
memset(p_fic_ecr->nom ,0,p_fic_ecr->longueur);
strcpy(p_fic_ecr->nom , p_fic_lu->nom);
strcat(p_fic_ecr->nom, "_OUT");
printf("Fichier en écriture %s \n\n",p_fic_ecr->nom);
p_fic_lu->p_fic = fopen(p_fic_lu->nom, "r");
//file = fopen(p_fic_lu->nom, "r");
//if (file == NULL) {
if (p_fic_lu->p_fic == NULL) {
printf("Absence du fichier %s ou problèmede lecture \n\n",p_fic_lu->nom);
free(p_fic_lu->nom);
free(p_fic_ecr->nom);
return EXIT_FAILURE; //fin de traitement
}
count=0;
nb_blocks = 0; //
while (1) {
c=fgetc( p_fic_lu->p_fic);
if (c == EOF || count == TAILLE_MAX) {
buffer[count] = '\0';
++nb_blocks;
if (buffer[0]=='2' )
{
if ( buffer[35] == 'A') {
printf("Block A2%d:\n%s\n\n", nb_blocks, buffer);
/* vidage 119-128 10A*/
for( i =118; i <= 127 ; ++i) buffer[i]= ' ';
printf("PostBlock A2%d:\n%s\n\n", nb_blocks, buffer);
}
}
//printf("Block %d:\n%s\n\n", nb_blocks, buffer);
if (c == EOF) break;
count=0;
}
buffer[count] = c; // cast implicite
count++;
}
fclose( p_fic_lu->p_fic);
//dealloaction des structures str_fichier
free(p_fic_lu->nom);
free(p_fic_ecr->nom);
return EXIT_SUCCESS;
} |
Partager