thanks a lot Salem,
I tried your code, it compile successfully, but still crushed by system.
By the way, this are my module implementations in allocating memory for every file. I didn't include the graphics implementation and the main module.
----------module for display the file in an inputted directory---------
fname is define outside this modules (char *fname), it is a holder for the current directory.
Code:
#include <dir.h>
#include <stdlib.h>
#include <graphics.h>
struct ffblk ffblk;
char **files;
void countMem_to_Alloc(){
int done,counter=0,i;
done = findfirst(fname,&ffblk,0);
while(!done){
done = findnext(&ffblk);
counter++;
}
files = malloc(counter * sizeof(char));
for(i=0;i<counter;i++) files[i] = malloc(50*sizeof(char));
}
void saveFiles(int* nDex){
int i,done;
countMem_to_Alloc();
done = findfirst(fname,&ffblk,0);
while(!done){
done = findnext(&ffblk);
strcpy(files[*nDex++],ffblk.ff_name);
}
}
void displayDir(){
int i,index=0,
chHeight = textheight("H"),
curX = 10,curY = 66;
saveFiles(&index);
setcolor(14);
settextstyle(2,0,0);
for(i=0;i<index;i++){
if(i==42){curX = 272;curY = 66;}
outtextxy(curX,curY,files[i]);
curY += chHeight;
}
for(i=0;i<index;i++)free(files[i]);
free(files);
}
thanks a lot man for your quick reply, this is actually our project program to be passed tomorrow.
hope you'll help with this.
thanks,
REYAL