Ajout des fichiers du jour 2

This commit is contained in:
Rick 2020-12-09 16:48:45 +01:00
parent 17da27f542
commit 1574aeb608
Signed by: Rick
GPG key ID: 9570A7DB7CB2F436
2 changed files with 1083 additions and 0 deletions

1000
jour2/input Normal file

File diff suppressed because it is too large Load diff

83
jour2/main.c Normal file
View file

@ -0,0 +1,83 @@
#include <stdio.h>
#include <stdlib.h>
#define FILENAME "input"
void premPartie(FILE *ptr);
void deuxPartie(FILE *ptr);
int main()
{
FILE *ptr = fopen(FILENAME, "r");
if (ptr == NULL)
{
return 1;
}
// commentez la première partie quand vout voulez exécuter la deuxième
// le curseur de lecture du fichier reste à la fin
//premPartie(ptr);
deuxPartie(ptr);
fclose(ptr);
return 0;
}
void deuxPartie(FILE *ptr)
{
int bornInf, bornSup;
int find = 0;
char speChar;
char word[256];
fscanf(ptr, "%d-%d %c: %s", &bornInf, &bornSup, &speChar, word);
while (!feof(ptr))
{
if ((word[bornInf - 1] == speChar && word[bornSup - 1] != speChar)
|| (word[bornInf - 1] != speChar && word[bornSup - 1] == speChar))
{
find++;
}
fscanf(ptr, "%d-%d %c: %s", &bornInf, &bornSup, &speChar, word);
}
printf("%d bons mdp trouvés.\n", find);
}
void premPartie(FILE *ptr)
{
int bornInf, bornSup, i, nbOcc;
int find = 0;
char speChar, readChar;
char word[256];
fscanf(ptr, "%d-%d %c: %s", &bornInf, &bornSup, &speChar, word);
while (!feof(ptr))
{
i = 0;
nbOcc = 0;
readChar = word[i];
while (readChar != '\0')
{
if (readChar == speChar)
{
nbOcc++;
}
i++;
readChar = word[i];
}
if (nbOcc >= bornInf && nbOcc <= bornSup)
{
find++;
}
fscanf(ptr, "%d-%d %c: %s", &bornInf, &bornSup, &speChar, word);
}
printf("%d bons mdp trouvés.\n", find);
}