Skip to content

Instantly share code, notes, and snippets.

@CrBoy
Created March 1, 2011 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrBoy/848895 to your computer and use it in GitHub Desktop.
Save CrBoy/848895 to your computer and use it in GitHub Desktop.
This is a funny tool to encode a UTF-8 file to only ascii charactors.
Therefore we can write C code by Chinese with some definition.
Issues:
In the Makefile, I'd like to create a automatical building,
but I forget how to use variables to indicate the names.
#include <stdio.h>
#define _E695B4_E695B8 int
#define _E5AD97_E58583 char
#define _E5B8B8_E695B8 const
#define _E59B9E_E582B3 return
#define _E4B8BB_E8A681 main
#define _E58DB0_E587BA printf
_E695B4_E695B8 _E4B8BB_E8A681(_E695B4_E695B8 argc, _E5B8B8_E695B8 _E5AD97_E58583 *argv[])
{
_E695B4_E695B8 _E8AE8A_E695B81 = 12;
_E58DB0_E587BA("%d\n", _E58AA01(_E8AE8A_E695B81));
_E59B9E_E582B3 0;
}
_E695B4_E695B8 _E58AA01(_E695B4_E695B8 _E794B2)
{
_E59B9E_E582B3 _E794B2+1;
}
#include <stdio.h>
int leading_ones(unsigned char c);
void print_hex(unsigned char c);
int main(int argc, const char *argv[])
{
unsigned char c;
int count;
while(scanf("%c", &c)!=EOF){
count = leading_ones(c);
if(count==0){
fputc(c, stdout);
}else if(count==1){
fputc(c, stdout);
}else{
fputc('_', stdout);
print_hex(c);
while(--count){
scanf("%c", &c);
print_hex(c);
}
}
}
return 0;
}
int leading_ones(unsigned char c)
{
unsigned mask = 0x80;
int count = 0;
while(mask & c)
mask >>= 1, ++count;
return count;
}
void print_hex(unsigned char c)
{
static char hnum[17]="0123456789ABCDEF";
fputc(hnum[c>>4], stdout);
fputc(hnum[c&0x0f], stdout);
}
#include <stdio.h>
#define 整數 int
#define 字元 char
#define 常數 const
#define 回傳 return
#define 主要 main
#define 印出 printf
整數 主要(整數 argc, 常數 字元 *argv[])
{
整數 變數1 = 12;
印出("%d\n", 加1(變數1));
回傳 0;
}
整數 加1(整數 甲)
{
回傳 甲+1;
}
encoding_utf8: encoding_utf8.c
gcc -o encoding_utf8 encoding_utf8.c
# I forget how to use variables....orz
#enc-$.c: encoding_utf8 $.c
# ./encoding_utf8 <$.c >enc-$.c
#
#$: enc-$.c
# gcc -o $ enc-$.c
@yuxuanchen1997
Copy link

少了一行,

整數 加1(整數 那個數字);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment