Witam!
Wiem, że jest to temat znany, ale mimo tego nie znalazłem odpowiedniego rozwiązania. Oto kod:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "pl_PL");
const int lineLength = 100;
char line[lineLength];
int howMuchDigits = 0;
int howMuchLetters = 0;
int i;
while(gets(line) != NULL)
{
for(i = 0; i < lineLength; i++)
{
if(isdigit(line[i]))
howMuchDigits++;
else if(isalpha(line[i]))
howMuchLetters++;
else if(line[i] == '\0')
break;
}
}
printf("%i %i", howMuchLetters, howMuchDigits);
return 0;
}
Problem w tym że gdy w konsoli wpiszę polskie znaki, to program je ignoruje i w efekcie ich nie zlicza. Pomimo użycia funkcji setlocale, która w Visual Studio (w C++) rozwiązywała problem. Czy może mi ktoś wyjaśnić dlaczego ten kod nie działa tak jak powinien?
Z góry dziękuję za pomoc :-)