2020-12-14 17:03:37 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
//#include <stdlib.h>
|
|
|
|
//#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
void prem_partie(FILE *ptr)
|
|
|
|
{
|
|
|
|
int total = 0, find = 0;
|
2020-12-14 17:42:20 +01:00
|
|
|
char act_line[30], find_char[26], empty[26];
|
2020-12-14 17:03:37 +01:00
|
|
|
char tmp;
|
2020-12-14 17:42:20 +01:00
|
|
|
fscanf(ptr, "%s", act_line);
|
2020-12-14 17:03:37 +01:00
|
|
|
|
|
|
|
while (!feof(ptr))
|
|
|
|
{
|
2020-12-15 18:41:27 +01:00
|
|
|
for (int i = 0; i < (int) strlen(act_line); i++)
|
2020-12-14 17:03:37 +01:00
|
|
|
{
|
2020-12-14 17:42:20 +01:00
|
|
|
tmp = act_line[i];
|
|
|
|
if (strchr(find_char, act_line[i]) == NULL)
|
2020-12-14 17:03:37 +01:00
|
|
|
{
|
|
|
|
find++;
|
2020-12-14 17:42:20 +01:00
|
|
|
strncat(find_char, &tmp, 1);
|
2020-12-14 17:03:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_void_line(ptr))
|
|
|
|
{
|
|
|
|
total += find;
|
|
|
|
find = 0;
|
2020-12-14 17:42:20 +01:00
|
|
|
strcpy(find_char, empty);
|
2020-12-14 17:03:37 +01:00
|
|
|
}
|
2020-12-14 17:42:20 +01:00
|
|
|
fscanf(ptr, "%s", act_line);
|
2020-12-14 17:03:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("La somme de toutes les réponses est : %d.\n", total);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deux_partie(FILE *ptr)
|
|
|
|
{
|
2020-12-14 17:42:20 +01:00
|
|
|
int total = 0, find = 0, first = 1;
|
|
|
|
char act_line[30], find_char[26], empty[26];
|
|
|
|
char tmp;
|
|
|
|
fscanf(ptr, "%s", act_line);
|
|
|
|
|
|
|
|
while (!feof(ptr))
|
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
strcpy(find_char, act_line);
|
|
|
|
find = strlen(find_char);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
tmp = find_char[i];
|
|
|
|
|
|
|
|
while (tmp != '\0')
|
|
|
|
{
|
|
|
|
if (strchr(act_line, tmp) == NULL && tmp != '!')
|
|
|
|
{
|
|
|
|
find--;
|
|
|
|
find_char[i] = '!';
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
tmp = find_char[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_void_line(ptr))
|
|
|
|
{
|
|
|
|
total += find;
|
|
|
|
find = 0;
|
|
|
|
first = 1;
|
|
|
|
strcpy(find_char, empty);
|
|
|
|
}
|
|
|
|
fscanf(ptr, "%s", act_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("La somme de toutes les réponses est : %d.\n", total);
|
2020-12-14 17:03:37 +01:00
|
|
|
}
|