-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearch_file.c
40 lines (32 loc) · 958 Bytes
/
Search_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define DATA_SIZE 1000
//optional delay function
void delay(int number_of_seconds) {
int milli_seconds = 1000 * number_of_seconds;
clock_t start_time = clock();
while (clock() < start_time + milli_seconds);
}
void search() {
FILE *fPtr;
printf("Enter Name: ");
char account_name[DATA_SIZE];
scanf("%s", account_name);
while ((getchar()) != '\n');
printf("\nSearching File...\n");
delay(1100); //Made as to not overwhelm the user
printf("========================================\n\n");
char suffix[] = ".txt";
strcat(account_name, suffix);
fPtr = fopen(account_name, "r");
char c;
c = fgetc(fPtr);
while (c != EOF) { //Go through the entire file and display everything
printf("%c", c);
c = fgetc(fPtr);
}
printf("========================================\n");
fclose(fPtr);
}