Hi Srini,
By what i can understand thius is your requirement.
A program which opens file on demand, reads the content, prints it if
asked for and at exit cleans up the memory used.
I am slightly modifying the structure
u can use this
typedef struct _files
{
char * data;
int fd;
} *pfile;
then sonewhere in main u can say
int main(){
pfile pf;
// U can maintain a seperate variable for storing the number of files.
pf = malloc(some initial number of files);
while ( no more files to be procesed )
{
// get the file name;
// run "stat" on the file, and get the file size
// pf[i].fd = open(current file, O_RDONLY);
// pf[i].data = malloc(file size);
// processing...
}
then in a simple for loop before exit u can just do the closing /
deleting the files and freeing up the memory.
}
U need to use
stdio.h, stdlib.h, malloc.h, fcntl.h, sys/stat.h, sys/types.h
Hope u get the logic.
-Vighnesh
srini wrote:
Hi
I need to create two-dimensional array; number of rows and columns
unknown at compile time. The idea is to read a file, print it if
requested by user and to delete when the program quits.
Here is what I came up with using C:
struct diskinfo {
char **part_name; /* name of each partition */
int **num_blocs;
}
I need only one instance of 'diskinfo' in the program. What is the best
way to create & free memory and what are the C libraries that I should
include for this ?
Thanks for your time and help
-Srini