problem with pointer and string - function

C

collinm

hi

i got some error with parameter

my searchFile function:

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:

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,

led_display.c: In function `readFile':
warning: passing arg 1 of `close' makes integer from pointer without a
cast
warning: passing arg 2 of `analyzeFilename' from incompatible pointer
type
warning: passing arg 3 of `analyzeFilename' from incompatible pointer
type
warning: passing arg 1 of `close' makes integer from pointer without a
cast


in the analyzeFilename function i want to use filename and line

any idea?
 
C

CBFalconer

collinm said:
.... snip ...

in this function,

led_display.c: In function `readFile':
warning: passing arg 1 of `close' makes integer from pointer without a cast
warning: passing arg 2 of `analyzeFilename' from incompatible pointer type
warning: passing arg 3 of `analyzeFilename' from incompatible pointer type
warning: passing arg 1 of `close' makes integer from pointer without a cast

in the analyzeFilename function i want to use filename and line

any idea?

There are no such functions as 'close' or 'analyzeFilename' in
standard C. To discuss their use here you have to show their
source, written in standard C. The other alternative is to go to a
newsgroup that discusses your actual system.

I suspect you want to use fclose in place of close. The rest is a
mystery.
 
T

tigervamp

collinm said:
hi

i got some error with parameter

my searchFile function:

char *tmp[2];
int size[2];
...
in this function,

led_display.c: In function `readFile':
warning: passing arg 1 of `close' makes integer from pointer without a
cast
warning: passing arg 2 of `analyzeFilename' from incompatible pointer
type
warning: passing arg 3 of `analyzeFilename' from incompatible pointer
type
warning: passing arg 1 of `close' makes integer from pointer without a
cast

in the analyzeFilename function i want to use filename and line

any idea?

You opened the file with fopen, use fclose to close the file. close is
probably a system call (it is not a Standard C function) expecting a
numeric file descriptor, hence the warning. You didn't include a
prototype for the analyzeFilename function so we have no idea what is
it expecting but it obviously isn't the same as what you are passing
it. If you want more help, show us the analyzeFilename function or at
least the prototype.

Most of the code you posted is not related to the question you asked,
you should reduce the issue to the smallest complete program that
exhibits the problem and post that code with your questions.

Rob Gamble
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top