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
|
void
getfilecontent ()
{
long lenfic;
int j, l;
char *tab, *pstr, *istr;
FILE *fic;
fic = fopen ("fic.txt", "r");
if (fic != NULL)
{
fseek (fic, 0L, SEEK_END);
lenfic = ftell (fic);
tab = malloc (lenfic);
if (tab == NULL)
{
perror ("malloc");
return;
}
fread (tab, 1, lenfic, fic);
if (fclose (fic) != 0)
{
perror ("fclose");
}
istr = tab;
while ((pstr = strchr (istr, '\n')) != NULL)
{
nbrlines++;
*pstr = 0;
istr = pstr + 1;
}
for (j = 0, l = 0; j < nbrlines; j++, l += strlen (tab[l]) + 1)
{
printf ("%s\n", tab[l]);
}
}
free (tab);
} |
Partager