0

I have a function that takes in a text file and I want to loop through the characters and check if a character is an emoji or not. I have this code to loop though the characters:

 while ((c = fgetc(input_fd)) != EOF) { //input_fd is of type FILE *
    printf("%c", c);
    if () { //If character is emoji
        printf("Invalid: %c \n", c);
    }
}

What would I have to put in the if statement to check if c is an emoji or not?

Simon
  • 11
  • 4
  • 2
    Combine https://stackoverflow.com/questions/605985/how-to-check-if-a-unicode-character-is-within-given-range-in-c and https://stackoverflow.com/a/36258684/529282 – Martheen Oct 02 '20 at 01:45
  • 3
    `a text file` You need to know the encoding of the file before worrying about emojis. – dxiv Oct 02 '20 at 01:47
  • 2
    Are you looking for valid emoji specifically, or a more general class of invalid characters? Maybe only some characters are valid? – Ry- Oct 02 '20 at 02:03
  • @Ry- just whether a character is any kind of emoji or not. – Simon Oct 02 '20 at 02:39
  • 1
    This problem is non-trivial. You'll probably need to read the file as a specific type of character encoding, then convert each group of bytes into a Unicode code point. Then you'll have to test each code point for whether it's an emoji, and that will testing for a whole list of arbitrary numbers. Reading a file char-by-char won't help you, because emojis are all likely to be encoded as multiple bytes. – Kevin Boone Oct 02 '20 at 07:18

0 Answers0