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 1 1 6 5 0 0 0

0 0 0 0 4 4 0 0 0 0 0 0 5 8 9 9 8 5 0 0 5 6 0 0 6 5 0 0 0 0

0 0 0 0 5 5 0 0 0 0 0 0 5 8 9 9 8 5 0 0 0 0 6 6 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 5 8 9 9 8 5 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 5 8 9 9 8 5 0 0 0 0 0 0 0 0 0 0 0 0
*/
void convert(char ch) ;

int main(void)
{
? ? FILE *fp;
? ? char file_name[MAX];
? ? char ch;
? ??
? ? scanf("%s",file_name);
? ? if ((fp = fopen(file_name, "r")) == NULL)
? ? {
? ? ? ? fprintf(stdout,"Can't open \"wordy\" file.\n");
? ? ? ? exit(EXIT_FAILURE);
? ? }
? ? while((ch = getc(fp))!=EOF)
?? ??? ?convert(ch);
? ? fclose(fp);
? ? return 0;
}

void convert(char ch)?
{
?? ?int n;
?? ??? ?
?? ?if(ch=='\n')
?? ?{
?? ??? ?putchar('\n');
?? ?}
?? ?else
?? ?{
?? ??? ?n = ch-'0';
?? ??? ?switch(n)
?? ??? ?{
?? ??? ??? ?case 0:putchar(' ');break;
?? ??? ??? ?case 1:putchar('.');break;
?? ??? ??? ?case 2:putchar('\'');break;
?? ??? ??? ?case 3:putchar(':');break;
?? ??? ??? ?case 4:putchar('~');break;
?? ??? ??? ?case 5:putchar('*');break;
?? ??? ??? ?case 6:putchar('=');break;
?? ??? ??? ?case 7:putchar('+');break;
?? ??? ??? ?case 8:putchar('%');break;
?? ??? ??? ?case 9:putchar('#');break;
?? ??? ??? ?default:putchar(' ');break;
?? ??? ?}

?? ?}

}

文章来源:https://blog.csdn.net/apple_50569014/article/details/135766623
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。