锘??xml version="1.0" encoding="utf-8" standalone="yes"?>/**//*
* Name: IP Address
* Funcion: To convert binary numbers to decimal numbers
* Input: 00000011100000001111111111111111
* Output: 3.128.255.255
*/
#include <stdio.h>
void main()
{
char input[32];
int output[4];
int count = -1;
int i;
for(i = 0; i < 4; i++ )
output[i] = 0;
gets( input );
for( i = 0; i < 32; i++ )
{
if( i % 8 == 0 )
count++;
if( input[i] == '1' )
{
switch( i % 8 )
{
case 0:
output[count] += 128;
break;
case 1:
output[count] += 64;
break;
case 2:
output[count] += 32;
break;
case 3:
output[count] += 16;
break;
case 4:
output[count] += 8;
break;
case 5:
output[count] += 4;
break;
case 6:
output[count] += 2;
break;
case 7:
output[count] += 1;
break;
default:
break;
}
}
}
printf( "%d.%d.%d.%d\n", output[0], output[1], output[2], output[3] );
}
]]>
鏂規硶涓錛氫嬌鐢╛itoa鍑芥暟
#include "stdio.h"
2#include "stdlib.h"
3
4void int2str(int , char *);
5
6int main()
7 {
8int i = 123;
9char s[64];
10int2str(i, s);
11puts(s);
12}
13
14void int2str(int i, char *s)
15 {
16_itoa(i, s, 10);
17}
]]>/**//**************************************************************************
2鍔熻兘 錛?nbsp;CRC鏍¢獙璁$畻
3杈撳叆鍙傛暟 錛?nbsp;unsigned char *ptr--闇瑕佹牎楠岀殑鏁版嵁
5杈撳嚭鍙傛暟 錛?nbsp;unsigned char len--鏍¢獙鏁版嵁闀垮害
7榪斿洖鍊?nbsp; 錛氭牎楠屽?br> 8
**************************************************************************/
9unsigned int CGlobalData::Cal_CRC(unsigned char *ptr, unsigned char len)
10{
11 unsigned char i;
12 unsigned int crc=0;
13 while(len--!=0)
14
{
15 for(i=0x80; i!=0; i/=2)
16
{
17 if((crc&0x8000)!=0)
18
{
19 crc*=2;
20 crc^=0x18005;
21 }
22 else
23
{
24 crc*=2;
25 }
26
27 if((*ptr&i)!=0)
28
{
29 crc^=0x18005;
30 }
31 }
32 ptr++;
33 }
34 return(crc); //榪斿洖鍊煎悗鍗佸叚浣嶄負鏍¢獙鍊?/span>
35}
]]>
//鍦ㄥ瓧絎︿覆涓鎵懼瓙瀛楃
int strindex(char *str,char *substr)
{
int end,i,j;
end = strlen2(str)-strlen2(substr);
if (end>0)
{
for(i=0;i<=end;i++)
/*浣跨敤寰幆姣旇緝*/
for(j=i; str[j]==substr[j-i];j++)
if (substr[j-i+1]=='\0')
return i+1;
}
return -1;
}
//涓葷▼寮忥細鍦ㄥ瓧絎︿覆涓鎵懼瓙瀛楃涓插嚭鐜扮殑浣嶇疆
void main()
{
char string[100];
char substring[100];
int result;
printf("璇瘋緭鍏ュ瓧絎︿覆");
gets(string);
printf("璇瘋緭鍏ヨ鎼滅儲鐨勫瓙瀛楃涓?);
gets(substring);
result = strindex(string,substring);
if (result > 0)
printf("瀛愬瓧絎︿覆浣嶇疆鍦?d",result);
else
printf("娌℃湁鎵懼埌");
getchar();
}