TheObserver
Programmer
I am doing a strcmp on a filename returned from a directory pointer. However, the comparisons don't seem to work, and the program flows straight through (and thus all of the logic evaluates to "true"
until it hits the exit(1) in the code below. Any ideas on why the logic isn't working right?
while ( (direntp = readdir( dirp )) != NULL )
{
printf("\n\nhello\n\n\n"
;
if ( strcmp ( direntp->d_name, "." ) == 0 ||
strcmp ( direntp->d_name, ".." ) == 0 )
{
if(consoleout)
{
printf("Invalid input file.\n"
;
}
}
// if((strcmp(direntp->d_name, "."
!= 0) && (strcmp(direntp->d_name, ".."
!= 0))
else
{
printf("\n\nframe file: %s\n",direntp->d_name);
printf("strcmp %i\n",strcmp(direntp->d_name,"."
);
printf("strcmp %i\n",strcmp(direntp->d_name,".."
);
//test our first argument and see what it is.
if ((ffptr = fopen( direntp->d_name, "r" )) == NULL)
{
if(consoleout)
{
printf("\nError opening input frame file: %s\n",direntp->d_name);
}
exit(1);
}
//do stuff
}
I get the following output to my console:
______
% ./test /home/
hello
frame file: .
strcmp -55
strcmp -68
Error opening input frame file: .
______
Thanks for your time.
while ( (direntp = readdir( dirp )) != NULL )
{
printf("\n\nhello\n\n\n"
if ( strcmp ( direntp->d_name, "." ) == 0 ||
strcmp ( direntp->d_name, ".." ) == 0 )
{
if(consoleout)
{
printf("Invalid input file.\n"
}
}
// if((strcmp(direntp->d_name, "."
else
{
printf("\n\nframe file: %s\n",direntp->d_name);
printf("strcmp %i\n",strcmp(direntp->d_name,"."
printf("strcmp %i\n",strcmp(direntp->d_name,".."
//test our first argument and see what it is.
if ((ffptr = fopen( direntp->d_name, "r" )) == NULL)
{
if(consoleout)
{
printf("\nError opening input frame file: %s\n",direntp->d_name);
}
exit(1);
}
//do stuff
}
I get the following output to my console:
______
% ./test /home/
hello
frame file: .
strcmp -55
strcmp -68
Error opening input frame file: .
______
Thanks for your time.