ras le bol

This commit is contained in:
2026-02-23 01:15:30 +01:00
parent fba51abae3
commit 28dee070b3
38 changed files with 442 additions and 321 deletions
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <string.h>
int my_grep(char *filename, char *expr){
FILE *file = fopen(filename, "r");
if(!file) return 2;
char buffer[2048];
int found = 0;
while(fgets(buffer, sizeof(buffer), file)){
if(strstr(buffer, expr) != NULL){
printf("%s", buffer);
if(buffer[strlen(buffer) - 1] != '\n') printf("\n");
found ++;
}
}
fclose(file);
if (found != 0) return 1;
return 0;
}
/*
int main()
{
printf("\n%d\n", my_grep("example.txt", "word"));
// Expected:
//This line contains words.
//And "words" contains "word".
//word
//1
putchar('\n');
printf("%d\n", my_grep("example.txt", "eqlijgber")); // Returns 0
printf("%d\n", my_grep("empty_file.txt", "word")); // Returns 0
printf("%d\n", my_grep("inexisting_file.txt", "word")); // Returns 2
putchar('\n');
// FLAG
//Try "grepping" the flag.csv file, by the credit card numbers you found in
//the previous flag.
//Then, only keep those which booked several entries.
my_grep("flag.csv", "Put here the credit card numbers");
my_grep("flag.csv", "Put here the credit card numbers");
my_grep("flag.csv", "Put here the credit card numbers");
my_grep("flag.csv", "Put here the credit card numbers");
my_grep("flag.csv", "Put here the credit card numbers");
return 0;
}
*/