eslmz 0 Newbie Poster

I use a non english keyboard and i'm writing a console program. When i want to check a non english character with using getch, it returns wrong ASCII values(it gives the same number for different characters). But when i try to use getchar, it returns the true ASCII numbers. But i can't interrupt the getchar without pressing Enter. Here is my code that works for only English characters

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>

int main() {
   char str[11]; 
   int ch,i = 0 , hata , sayi;

   printf("input maximum 10 chars: ");
   do {
      ch = getch();
      fflush(stdin);
      if (ch == '\b' && i > 0) {
         printf("\b \b");
         fflush(stdout);
         i--;
         str[i] = '\0';
      } else if (isalpha(ch) != 0) {
         printf("%c",ch);
         str[i++] = (char)ch;
      }
   } while (ch != EOF && ch != '\n' && ch != '\r' && i < sizeof(str) - 1);
   str[i] = '\0';

   printf ("\nOur string %s", str);
   getch();
   return 0;
}

Do you have any suggestions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.