replica en avancement

This commit is contained in:
hexplor
2026-03-31 05:51:18 +02:00
parent 4880d13bbd
commit b16bc96a61
2 changed files with 17 additions and 15 deletions
BIN
View File
Binary file not shown.
+17 -15
View File
@@ -77,7 +77,7 @@ static int search_end(FILE* file){
return -1; return -1;
} }
static int insert_into_section(FILE* file, const char* name_out, const char* toInsert, int nbLine){ static int insert_into_section(FILE* file, const char* name_out, const char* toInsert){
if (strlen(name_out) > 48) if (strlen(name_out) > 48)
return -1; return -1;
int end = search_end(file); int end = search_end(file);
@@ -91,12 +91,22 @@ static int insert_into_section(FILE* file, const char* name_out, const char* toI
} }
printf("%s: name_concat for the moment: %s\n", __FUNCTION__, name_concat); printf("%s: name_concat for the moment: %s\n", __FUNCTION__, name_concat);
FILE* out = fopen(name_concat, "w"); FILE* out = fopen(name_concat, "w");
if (end != -1){ printf("%s: ecriture du fichier avec %s a insere a la ligne %d\n", __FUNCTION__, toInsert, end);
printf("%s: end recupere\n", __FUNCTION__); fseek(file, 0, SEEK_SET);
} int count = 0;
else{ char* line = NULL;
printf("%s: end non trouve\n", __FUNCTION__); size_t rded = 0;
while (1){
if (count == end)
fprintf(out, "%s\n", toInsert);
if (getline(&line, &rded, file) == -1)
break;
fprintf(out, "%s", line);
free(line);
line = NULL;
count++;
} }
fclose(out); fclose(out);
return 0; return 0;
} }
@@ -111,15 +121,7 @@ int main(int argc, char **argv)
size_t rded = 0; size_t rded = 0;
if (!in) if (!in)
return 1; return 1;
while (1){ insert_into_section(in, argv[1], "INSERTED");
if (getline(&line, &rded, in) == -1)
break;
//printf("%s", line);
free(line);
line = NULL;
}
int end_line_count = search_end(in);
insert_into_section(in, argv[1], "INSERTED", end_line_count);
free(line); free(line);
fclose(in); fclose(in);
return 0; return 0;