易截截图软件、单文件、免安装、纯绿色、仅160KB

c代码:电话号码和字母转换

这两天看到有人讨论电话键盘上的字母、号码和字母的转换,我也随便写了一段
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_LEN 15
char *tbl_itoa[] =
{
"0", // 0
"1", // 1
"ABC", // 2
"DEF", // 3
"GHI", // 4
"JKL", // 5
"MNO", // 6
"PQRS", // 7
"TUV", // 8
"WXYZ" // 9
};
int tbl_atoi['Z'-'A'+1] = {0};
void init_tbl()
{
int c;
int i;
for (c='A'; c<='Z'; c++)
{
for (i=0; i<=9; i++)
{
if (strchr(tbl_itoa[i], c) != NULL)
{
tbl_atoi[c-'A'] = i;
break;
}
}
}
#if 0 // DEBUG
for (c='A'; c<='Z'; c++)
{
printf("%c %d\n", (char)c, tbl_atoi[c-'A']);
}
#endif
}
void to_digits(const char *s);
void to_alpha(const char *s);
int is_all_digits(const char *s);
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Usage: %s STRING\n", argv[0]);
return 1;
}
if (strlen(argv[1]) > MAX_LEN)
{
printf("string too long. only %d allowed\n", MAX_LEN);
return 1;
}
init_tbl();
if (is_all_digits(argv[1]))
to_alpha(argv[1]);
else
to_digits(argv[1]);
return 0;
}
int is_all_digits(const char *s)
{
char c;
while ((c=*s++) != '\0')
if (!isdigit(c))
return 0;
return 1;
}
void to_digits(const char *s)
{
char c;
while ((c=*s++) != '\0')
{
if (islower(c))
c = toupper(c);
if (isupper(c))
printf("%d", tbl_atoi[(int)(c-'A')]);
else
printf("%c", c);
}
printf("\n");
}
void to_alpha(const char *s)
{
char *p;
static char result[MAX_LEN+2] = {0};
static int idx = 0;
if (!isdigit(*s))
{
result[idx] = '\0';
printf("%s\n", result);
idx--;
return;
}
p = tbl_itoa[(int)(*s-'0')];
while(*p)
{
result[idx++] = *p;
to_alpha(s+1);
p++;
}
idx--;
}


相关文档:

C_简单的子函数调用

 源码:
# include <stdio.h>
 
/* 子函数声明 */
int square(int x); // 实现求平方值的子函数
int cube(int y);   // 实现求立方值的子函数
 
int main()
{
    int m = 12;
    int n = 4;
    printf("%d %d\n", sq ......

virtualBox 大搬家 从C盘移走

 即使将VirtualBox安装到别的盘上,其做成的虚拟机(系统,硬盘)仍会默认生成到系统盘,默认C:盘上,随着虚机数量和内容增加挤占了本来就不大的系统盘空间,很是不便。
 开始将C:盘下.VirtualBox目录下的东西全盘拷贝至别处,然后在VirtualBox的文件/环境设置 中将『默认硬盘目录』和『默认假想机器』做相应的修 ......

在LINUX下进行C语言编程所需要的基础知识

 这篇文章介绍在LINUX下进行C语言编程所需要的基础知识.在这篇文章当中,我们将会学到以下内容:
源程序编译
Makefile的编写
程序库的链接
程序的调试
头文件和系统求助
--------------------------------------------------------------------------------
1.源程序的编译
在Linux下面,如果要编译一个C ......

几种出色的C/C++ GUI函数库的介绍

 
QT
http://www.trolltech.com
http://www.qiliang.net/qt.html
Qt是Trolltech公司的一个多平台的C++图形用户界面应用程序框架。它提供给应用程序开发者建立艺术级的图形用户界面所需的所用功能。Qt是完全面向对象的很容易扩展,并且允许真正地组件编程。自从1996年早些时候,Qt进入商业领域,它已经成为全世界范 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号