I also Wrote this C++ code to search for files on your computer, and tell you where on your hard disk the file is located.
It is compatible only with windows.
Code:
//This will Search your hard disk for the document specified, and tells you where it is
//located
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define s_buffer 80
char *flush(char *);
int main(int argc, char *argv[])
**
char
string_to_lookfor[s_buffer],
string_searching[s_buffer],
filename[s_buffer],
temp_string[s_buffer];
long unsigned int
search_number=0,
for_i,
for_j, //special variables for the for loop
for_k;
FILE *search_file;
printf("What File Would You Like To Search?\n:");
fgets(filename, s_buffer, stdin);
if(strlen(filename) == 0 || strcmp(filename, "\n") == 0)
**
printf("You did not Enter a string, Program exitting.\n");
exit(0);
}
strcpy(filename, flush(filename));
search_file = fopen(filename, "r");
if(search_file == NULL)
**
perror(search_file);
exit(0);
}
printf("\nWhat are you searching for?\n:");
fgets(string_to_lookfor, s_buffer, stdin);
if(strlen(string_to_lookfor) == 0 || strcmp(string_to_lookfor, "\n") == 0)
**
printf("You did not Enter a string, Program exitting.\n");
exit(0);
}
strcpy(string_to_lookfor, flush(string_to_lookfor)); \n
search_number = strlen(string_to_lookfor);
for(for_i=0; !feof(search_file); for_i++)
**
fgets(string_searching, s_buffer, search_file);
if(strlen(string_searching) == 0 || strcmp(string_searching, "\n") == 0)
**
continue;
}
strcpy(string_searching, flush(string_searching));
for(for_j = 0; for_j < strlen(string_searching); for_j++)
**
for(for_k = 0; for_k < search_number; for_k++)
**
temp_string[for_k] = string_searching[for_k+for_j];
}
temp_string[for_k] = '\0';
if((strcmp(string_to_lookfor, temp_string)) == 0)
**
printf("Match Found For %s! It's On Line:%lu At Character:%lu\n",string_to_lookfor, for_i+1, for_j+1);
}
}
}
fclose(search_file);
return 0;
}
char *flush(char *string_flush)
**
if(string_flush[strlen(string_flush) - 1] == '\n')
**
string_flush[strlen(string_flush) - 1] = '\0'; \0
}
return string_flush;
}