GroceryBagHead
01-15-2003, 01:26 PM
This code should work, but I absolutely forgot how pointers work. So this is a bit messed up. Can somebody explain to me what I am doing wrong here?
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
void Searchie (char directory, char file2find) {
DIR *dp;
struct dirent *dirp;
dp = opendir(&directory);
while ((dirp=readdir(dp)) != NULL){
if (strcmp (dirp->d_name, &file2find) == 0)
printf ("Found it in %s\n", directory);
if (opendir(strcat(&directory, dirp->d_name)) != NULL && dirp->d_name!="." && dirp->d_name!="..")
Searchie (*strcat(&directory, dirp->d_name), file2find);
}
closedir(dp);
}
int main(int argc, char *argv[]) {
char *currentdir = "./";
if (argc == 1){
printf ("Please enter the file or directory to look for. Exiting.\n");
exit(0);
}
else Searchie(*currentdir, *argv[1]);
exit(0);
}
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
void Searchie (char directory, char file2find) {
DIR *dp;
struct dirent *dirp;
dp = opendir(&directory);
while ((dirp=readdir(dp)) != NULL){
if (strcmp (dirp->d_name, &file2find) == 0)
printf ("Found it in %s\n", directory);
if (opendir(strcat(&directory, dirp->d_name)) != NULL && dirp->d_name!="." && dirp->d_name!="..")
Searchie (*strcat(&directory, dirp->d_name), file2find);
}
closedir(dp);
}
int main(int argc, char *argv[]) {
char *currentdir = "./";
if (argc == 1){
printf ("Please enter the file or directory to look for. Exiting.\n");
exit(0);
}
else Searchie(*currentdir, *argv[1]);
exit(0);
}