hi
i got some error when i close file
my searchFile function:
Code:
char *tmp[2];
int size[2];
...
trouve++;
if( trouve == 1 ){
sleep(3);
printf("fic: %s\n", dirinfo->d_name);
size[0]=strlen(dirinfo->d_name);
if ( ( tmp[0] = malloc(size[0]) ) == NULL )
exit( EXIT_FAILURE );
tmp[0] = dirinfo->d_name;
}
else
{
size[1]=strlen(dirinfo->d_name);
if ( ( tmp[0] = malloc( size[1]) ) == NULL )
exit( EXIT_FAILURE );
tmp[1] = dirinfo->d_name;
readFile(fd, directory, tmp, strlen(directory), size);
/*do a pause*/
sleep(3);
free(tmp[0]);
free(tmp[1]);
free(tmp);
trouve==0;
}
...
my readFile function:
Code:
void readFile(int fd,char *directory, char *filename[], int sizedir, int sizefile[])
{
FILE *fp;
char line[LINE_MAX][2];
char *tmp;
int i;
int size[2];
//problème potentièle ? fin du tableau fini par \0 ?
for(i=0; i<2; i++)
{
if ( ( tmp = malloc( sizedir + sizefile[0] + 1) ) == NULL )
exit( EXIT_FAILURE );
strcpy(tmp, directory);
strcat(tmp, "/");
strcat(tmp, filename[0]);
fp = fopen(tmp, "r");
if(fp != NULL)
{
fgets(line[0], LINE_MAX, fp);
close(fp);
free(tmp);
if ( ( tmp = malloc( sizedir + sizefile[1] + 1) ) == NULL )
exit( EXIT_FAILURE );
strcpy(tmp, directory);
strcat(tmp, "/");
strcat(tmp, filename[1]);
/* On lie le fichier pour la deuxième ligne*/
fp = fopen(tmp, "r");
if(fp != NULL)
{
fgets(line[1], LINE_MAX, fp);
size[0]= strlen(line[1]);
size[1]= strlen(line[2]);
analyzeFilename(fd, *filename, line, size);
close(fp);
}
else
fprintf(stderr, "%s - Not able to open the file\n", strerror(errno));
}
else
fprintf(stderr, "%s - Not able to open the file\n", strerror(errno));
}
free(tmp);
}
in this function,
Code:
led_display.c: In function `readFile':
warning: passing arg 1 of `close' makes integer from pointer without a cast
warning: passing arg 1 of `close' makes integer from pointer without a cast
i try also to get the first character of *filename[ 0 ];
i do:
Code:
char *tmp;
tmp=filename[ 0 ];
printf("1 char: %s\n", *tmp);
i see: 1 char: (null)
any idea?