c语言初学者
编写一个程序
要求将输入的字母转化对应的12345
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define N 256
int main(int argc, char *argv[])
{
char s[N], m[128] = {0};
if (argc != 2 || strlen(argv[1]) < 26)
{
printf("%s <26-letters>\n", argv[0]);
return 1;
}
for (int i = 0; i < 26; i++)
{
m['a' + i] = tolower(argv[1][i]);
m['A' + i] = toupper(argv[1][i]);
}
while (fgets(s, N, stdin))
{
const char *p = s;
while (*p)
{
if (isalpha(*p))
putchar(m[(int)*p]);
else
putchar(*p);
p++;
}
}
return 0;
}
$ gcc -Wall main.c
$ ./a.out qwertyuiopasdfghjklzxcvbnm
I was scared of dentists
O vql leqktr gy rtfzolzl