Check out your help file for "findfirst()" and "findnext()", and everything else in dir.h (which you'll need to include).
In general:
use fgets() to take in the data from the user
remove the next to the last char newline with something like:
Code:
if(filenamearray[strlen(filenamearray)-1]=='\n')
filenamearray[strlen(filenamearray)-1]='0';
Then use the names you get from your program, to do a strcmp:
Code:
while(you still have more files) {
if((strcmp(filenamearray,filename))==0) { //are they the same?
print (found it) //yes
return 1
}
}
print (file not found)
return 0 //no
This is some Turbo C code that works on Windows XP, (right out of the help examples).
Put this with some of the above, add a little "logic glue", and you should be well on your way.
Code:
#include <stdio.h>
#include <dir.h>
int main(void)
{
struct ffblk ffblk;
int done;
printf("Directory listing of *.*\n");
done = findfirst("*.*",&ffblk,0);
while (!done)
{
printf(" %s\n", ffblk.ff_name);
done = findnext(&ffblk);
}
return 0;
}