Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tring to read a text file with emoji and print it

Input -> 😂😂

Output-> 😂😂

I simply want to maintain the original state of the emoji.

All i am doing is this

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

int main()
{
    char ch;
    FILE *fp;

    fp = fopen("test.txt","r");
    while( ( ch = fgetc(fp) ) != EOF )
        printf("%c",ch);

    fclose(fp);
return 0;
}
like image 507
karx Avatar asked Nov 09 '22 21:11

karx


1 Answers

In Unicode encoding, emoji must take more than one bytes. Hence printing byte by byte will not help in this case. If you redirect the output to a file, you may get almost same as your file.

You may try to print the string by changing locale(on Linux) or you can try wprintf on Windows (remember to convert to Wide string).

like image 85
doptimusprime Avatar answered Nov 14 '22 23:11

doptimusprime