-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.c
More file actions
45 lines (36 loc) · 768 Bytes
/
strings.c
File metadata and controls
45 lines (36 loc) · 768 Bytes
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
41
42
43
44
45
// strings
// all your binary are read by us
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MIN_STR_LEN 4
void print_strings(const char *filename){
FILE *file = fopen(filename, "rb");
if(!file){
perror("fopen");
exit(EXIT_FAILURE);
}
char buffer[1024];
int count = 0;
while(1){
size_t bytesRead = fread(buffer, 1, sizeof(buffer), file);
if(bytesRead == 0) break; // end of file
for(size_t i=0; i < bytesRead; i++){
if(isprint(buffer[i])){ // print if printable
putchar(buffer[i]);
count++;
} else {
if(count >= MIN_STR_LEN) {
putchar('\n'); // end of printable string seq
}
count = 0; //reset count
}
}
}
if(count >= MIN_STR_LEN){
putchar('\n');
}
fclose(file);
}
int main(void){
}