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,44 @@
#include <stdio.h>
int count(const char *filename){
FILE *file = fopen(filename, "r");
if(!file) return 1;
int words = 0;
int cara_word = 0; //cara pour compter les words
int cara = 0;
int lines = 0;
int c = fgetc(file);
while(c != EOF){
cara ++;
if(c == '\n') lines ++;
if (c != ' ' && c != '\n' && c != '\t' && c != EOF) cara_word ++;
else {
if (cara_word > 0) words ++;
cara_word = 0;
}
c = fgetc(file);
}
fclose(file);
printf("> characters: %i\n> words: %i\n> lines: %i\n", cara, words, lines);
return 0;
}
/*
int main()
{
return count("example.txt"); // <-- return 0, because example.txt exists
// Expected:
//> characters: 2030
//> words: 103
//> lines: 5
}
*/