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--;
}
Ïà¹ØÎĵµ£º
Ô´Â룺
# include <stdio.h>
void swap(int *x, int *y);
int main()
{
int i, j;
i = 12;
j = 36;
printf("i and j before swapping: %d %d\n", i, j);
&nbs ......
ÊéÖÐÓм¸¸öÎÊÌâÓеãÄ£ºý¡£¼Ç¼һÏ¡£
Answer to Exercise 1-7
Write a program to print the value of EOF .
#include <stdio.h>
int main(void)
{
printf("The value of EOF is %d\n\n", EOF);
return 0 ......
¼´Ê¹½«VirtualBox°²×°µ½±ðµÄÅÌÉÏ£¬Æä×ö³ÉµÄÐéÄâ»ú£¨ÏµÍ³£¬Ó²ÅÌ£©ÈÔ»áĬÈÏÉú³Éµ½ÏµÍ³ÅÌ£¬Ä¬ÈÏC:ÅÌÉÏ£¬Ëæ×ÅÐé»úÊýÁ¿ºÍÄÚÈÝÔö¼Ó¼·Õ¼Á˱¾À´¾Í²»´óµÄϵͳÅ̿ռ䣬ºÜÊDz»±ã¡£
¿ªÊ¼½«C:ÅÌÏÂ.VirtualBoxĿ¼ÏµĶ«Î÷È«ÅÌ¿½±´ÖÁ±ð´¦,È»ºóÔÚVirtualBoxµÄÎļþ/»·¾³ÉèÖà Öн«¡ºÄ¬ÈÏÓ²ÅÌĿ¼¡»ºÍ¡ºÄ¬ÈϼÙÏë»úÆ÷¡»×öÏàÓ¦µÄÐÞ ......
cÓëc++ staticº¯ÊýµÄÇø±ð
c
Óëc++ static
º¯ÊýµÄÇø±ð
static
¹Ø¼ü×ÖÊÇ
C, C++
Öж¼´æÔڵĹؼü×Ö
,
ËüÖ÷ÒªÓÐÈýÖÖʹÓ÷½Ê½
,
ÆäÖÐǰÁ½ÖÖÖ»Ö¸ÔÚ
C
ÓïÑÔÖÐʹÓÃ
,
µÚÈýÖÖÔÚ
C++
ÖÐʹÓÃ
(C,C++
ÖоßÌåϸ΢²Ù×÷²»¾¡Ïàͬ
,
±¾ÎÄÒÔ
C++
Ϊ׼
).
(1)
¾Ö²¿¾²Ì¬±äÁ¿
(2)
Íⲿ¾²Ì ......
---- ÔÚÊý¾Ý¿âµÄÓ¦Óÿª·¢ÖУ¬³£³£»áÓöµ½ÐÔÄܺʹú¼ÛµÄÖ®¼äì¶Ü¡£ÒÔ×÷ÕßÔÚ¿ª·¢¹ÉÊÐÐÐ
Çé²éѯºÍ½»Ò×ϵͳÖÐÓöµ½µÄÎÊÌâΪÀý£¬ÒªÔÚʵʱ¼Ç¼1000¶àÖ»¹ÉƱÿ·ÖÖÓ¸üÐÂÒ»´ÎµÄÐÐ
ÇéÊý¾ÝµÄͬʱ£¬ÏìÓ¦´óÁ¿²¢·¢Óû§µÄÊý¾Ý²éѯÇëÇ󡣿¼Âǵ½ÐԼ۱ȺÍÒ×ά»¤ÐÔ£¬ÏµÍ³ÓÖ
ÒªÇóÔÚ»ùÓÚPC·þÎñÆ÷£¬Windows NTƽ̨µÄÈíÓ²¼þ»·¾³ÏÂʵÏÖ¡£¿ª ......