易截截图软件、单文件、免安装、纯绿色、仅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>
# include <stdlib.h>
 
int main( )
{
    int select;
    int i, j;
    int score[5][7];
    int average = 0;
    int sum = 0;
  &n ......

virtualBox 大搬家 从C盘移走

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

linux下C语言多线程编程实例


兰大论坛上的一个帖子~~
学东西,往往实例才是最让人感兴趣的,老是学基础理论,不动手,感觉没有成就感,呵呵。
下面先来一个实例。我们通过创建两个线程来实现对一个数的递加。
或许这个实例没有实际运用的价值,但是稍微改动一下,我们就可以用到其他地方去拉。
下面是我们的代码:
/*thread_example.c : c ......

C/C++笔试题(1)

试题1:
Code
Void test1()
{
    char string[10];
    char* str1="0123456789";
    strcpy(string, str1);
}
试题2:
Code
Void test2()
{
    char string[10], str1[10];
 & ......

几种出色的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号