Thread: Check if non ASCII character is inputted

  1. #1
    Registered User
    Join Date
    Jun 2020
    Posts
    9

    Check if non ASCII character is inputted

    hello, I'm trying to put in my code to check if non ASCII character is a valid input if not get an error message.

    Code:
    #include <stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include<math.h>
    
    
    int key= 65;
    
    
    unsigned int easyendecrypt(char c);
    
    
    int main(void) {
        int c;
        while ((c = getc(stdin)) !=EOF) {
            putc(easyendecrypt(c), stdout);
        }
        key = 'A';
        printf("\n");
        return 0;
    }
    
    
    unsigned int easyendecrypt(char c) {
        unsigned int k;
    
    #ifdef DECRYPT
        fprintf(stderr, "decrypting with %c\n",key);
        k = c - key;
        key = k;
        return k;
    #else
        fprintf(stderr,"encrypting with %c\n",key);
        k = c + key;
        key = c;
        return k;
    #endif
    }
    

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    Lookup isprint() in ctype.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-02-2019, 11:07 AM
  2. Character to ASCII
    By larrydeloafer in forum C Programming
    Replies: 5
    Last Post: 02-28-2011, 05:39 PM
  3. Getting ASCII character warning
    By csonx_p in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2009, 02:02 PM
  4. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  5. Character to Ascii
    By tdep in forum C Programming
    Replies: 6
    Last Post: 07-10-2006, 03:07 PM

Tags for this Thread