Ajout 2e partie

This commit is contained in:
Rick 2020-12-14 17:42:20 +01:00
parent 7a7cd05563
commit a01237dc1b
Signed by: Rick
GPG key ID: 9570A7DB7CB2F436

View file

@ -8,19 +8,19 @@
void prem_partie(FILE *ptr) void prem_partie(FILE *ptr)
{ {
int total = 0, find = 0; int total = 0, find = 0;
char actLine[30], findChar[26], empty[26]; char act_line[30], find_char[26], empty[26];
char tmp; char tmp;
fscanf(ptr, "%s", actLine); fscanf(ptr, "%s", act_line);
while (!feof(ptr)) while (!feof(ptr))
{ {
for (int i = 0; i < strlen(actLine); i++) for (int i = 0; i < strlen(act_line); i++)
{ {
tmp = actLine[i]; tmp = act_line[i];
if (strchr(findChar, actLine[i]) == NULL) if (strchr(find_char, act_line[i]) == NULL)
{ {
find++; find++;
strncat(findChar, &tmp, 1); strncat(find_char, &tmp, 1);
} }
} }
@ -28,9 +28,9 @@ void prem_partie(FILE *ptr)
{ {
total += find; total += find;
find = 0; find = 0;
strcpy(findChar, empty); strcpy(find_char, empty);
} }
fscanf(ptr, "%s", actLine); fscanf(ptr, "%s", act_line);
} }
printf("La somme de toutes les réponses est : %d.\n", total); printf("La somme de toutes les réponses est : %d.\n", total);
@ -38,5 +38,45 @@ void prem_partie(FILE *ptr)
void deux_partie(FILE *ptr) void deux_partie(FILE *ptr)
{ {
int i; 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);
} }