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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int str_istr (const char *cs, const char *ct)
{
int index = -1;
if (cs && ct)
{
char *ptr_pos = NULL;
ptr_pos = strstr (cs, ct);
if (ptr_pos)
{
index = ptr_pos - cs;
}
}
return index;
}
int main (void)
{
FILE *f;
f = fopen("mon_fichier.txt", "rt");
if (f != NULL)
{
char line1[80] = "";
char line2[80] = "";
char *nom = NULL;
char *age = NULL;
char *tmp = NULL;
int pos;
fgets(line1, 80, f);
fgets(line2, 80, f);
fclose(f), f = NULL;
nom = &line2[1];
pos = str_istr (line2, ">");
line2[pos] = 0;
age = &line2[pos + 2];
pos = strlen(&line2[pos + 2]) - 1;
line2[pos] = 0;
printf(line1, nom, strtol(age, &tmp, 10));
printf("\n");
}
return 0;
} |
Partager