Ecco come ho modificato il codice:
codice:
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <conio.h>
#include <time.h>
#include <math.h>
int main(void)
{
char *buffer = NULL;
char **blocchi = NULL;
int in,out, nBlocchi=0, i, j, nRead;
int DIMBLOCCO = 64+1; // Un char in più per il terminatore di stringa
int numero;
if((in=open("elenco.txt", O_RDONLY))>=0)
{//inizia a leggere il file
buffer = (char *) malloc(DIMBLOCCO);
blocchi = (char **)malloc(DIMBLOCCO);
while( (nRead = read(in, buffer, DIMBLOCCO)) > 0 )
{
buffer[ nRead ] = '\0'; // Inserisco terminatore di stringa
nRead++; // La lunghezza è cresciuta +1 !
blocchi[nBlocchi] = (char *) malloc(nRead);
strncpy( blocchi[nBlocchi], buffer, nRead);
nBlocchi++;
}
printf("\n\nMostro stringhe\n\n");
for(i=0; i<nBlocchi; i++)
printf("%s\n", blocchi[i]);
close(in);
}
printf("%d", nBlocchi);
getchar();
getchar();
}
Perchè se vado a stampare il numero di blocchi... mi stampa 1???
Sto usando dev-c++ su winxp... è un problema del compilatore?