#include<stdio.h>
int len(char* s)
{
int length=0;
while (*s != 0)
{
s++;
length++;
}
return length;
}
char* strcpy(char* dest, char* src)
{
char* ret = dest;
while (*src != 0)
{
*dest = *src;
dest++;
src++;
}
return ret;
}
char* strcat(char* dest, char* src)
{
char* ret = dest;
while (*dest != 0)
{
dest++;
}
while (( * dest++ )= ( * src++));
return ret;
}
bool strcmp(char* dest, char* src)
{
bool b = true;
int len1 = 0;
int len2 = 0;
char* temp = dest;
while (*dest != 0)
{
dest++;
len2++;
}
dest = temp;
while (*dest == *src&&*dest!=0)
{
dest++;
src++;
len1++;
}
if (len1 != len2)
{
b = false;
}
return b;
}
int main()
{
char x[] = "china";
char y[] = "xyz";
printf("%d", strcmp(x, y));
getchar();
return 0;
}
#include<stdio.h>
char data[] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,
0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,
0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,
0x00,0x02,0x74,0x0F,0x41,0x00,0x06,0x08,0x00,0x00,
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00
};
void search(int type, int num)
{
char* pdata = data;
int length = sizeof(data) / sizeof(data[0]);
printf("data from:%x", pdata);
for (int i = 0; i < length - type; i++)
{
if (*(int*)(pdata+i) == num)
{
printf("address:%x value %d", pdata+i, num);
}
}
}
int main()
{
int type = 4;
int num = 100;
search(4, 100);
return 0;
}
#include<stdio.h>
char data[] =
{
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,
0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,
0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,
0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00,
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00
};
int len(char* name)
{
int ret = 0;
while (*name != 0)
{
name++;
ret++;
}
return ret;
}
bool strcmp(char* dest, char* src)
{
bool ret = true;
int length = len(dest);
int length2 = 0;
while (*dest==*src&&*dest!=0)
{
dest++;
src++;
length2++;
}
if (length != length2)
{
ret = false;
}
return ret;
}
char* searchName(char* pdata, char* name)
{
int length = sizeof(data) / sizeof(data[0]);
int namelen = len(name);
for (int i = 0; i < length - namelen; i++)
{
if (strcmp(name, pdata + i) == 1)
{
return pdata + i;
}
}
return 0;
}
void allprint(char* pdata, int type)
{
int length = sizeof(data) / sizeof(data[0]);
for (int i = 0; i < length - type; i++)
{
for (int j = 0; j < type; j++)
{
printf("%c", *(pdata + i + j));
}
printf("\n");
}
}
int main()
{
char name[] = "WOW";
printf("address:%x",searchName(data, name));
allprint(data,4);
return 0;
}
#include<stdio.h>
typedef struct TagPlayer
{
int id;
int level;
}Player;
char a[] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,
0x00,0x33,0x01,0x00,0x00,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,
0x00,0x00,0x64,0x01,0x00,0x00,0x00,0x08,0x00,0x00,
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,
0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00,
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00
};
TagPlayer* findtp(char* pa)
{
int length = sizeof(a);
TagPlayer* Ptp = (TagPlayer*)a;
printf("start:%x", Ptp);
for (int i = 0; i < length - 8; i++)
{
if (Ptp->id == 1 && Ptp->level == 8)
{
printf("find at:%x", Ptp);
}
Ptp=(TagPlayer*)((char*)Ptp+1);
}
return 0;
}
int main()
{
findtp(a);
return 0;
}