hello, i am trying to store a text from file into array to do some editing on it
i did this
void readFile(){
FILE *fp;
long lSize;
char *buffer;
fp = fopen ( "s.txt" , "rb" );
if( !fp ) perror("s.txt"),exit(1);
fseek( fp , 0L , SEEK_END);
lSize = ftell( fp );
rewind( fp );
/* allocate memory for entire content */
buffer = calloc( 1, lSize );
text= calloc (1,lSize);
if( !buffer )
{
fclose(fp);
fputs("memory alloc fails",stderr);
exit(1);
}
/* copy the file into the buffer */
if( 1!=fread( buffer , lSize, 1, fp) )
fclose(fp),free(buffer),fputs("entire read fails",stderr),exit(1);
fclose(fp);
}
now i need to use this array in the main function but i could not do that in anyway i am trying all the day but the content of array always dissapear out of the function readfile