#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
//int inet_pton(int af, const char *src, void *dst);
char * my_inet_aton(const char *input)
{
char *add_block[4];
int length = strlen(input);
int flag = 0;
int count[4];
static char result[40];
for(int i=0;i<4;i++)
{
add_block[i] = (char*)malloc(sizeof(char)*4);
}
memset(count,0,sizeof(int)*4); for(int i=0;i<length;i++)
{
if(input[i]!=':')
{
add_block[flag][count[flag]++] = input[i];
}
else
{
add_block[flag][count[flag]++]='\0';
flag++;
}
}
add_block[flag][count[flag]++] = '\0';
//int multi[4] = {256*256*256,256*256,256,1};
//for(int i=0;i<4;i++)
//{
//
// result += atoi(add_block[i])*multi[i];
//}
for(int i=0;i<4;i++)
{
strcat(result,add_block[i]);
//printf(add_block[i]);
}
//printf(result);
return result;
}
int inet_pton(af, src, dst)
{
int af;
const char *src;
void *dst;
switch (af) {
case AF_INET:
return (inet_pton4(src, dst));
case AF_INET6:
return (inet_pton6(src, dst));
default:
__set_errno (EAFNOSUPPORT);
return (-1);
}
/* NOTREACHED */
}
void fun(int a)
{
char* p = (char *)(&a);
for(int i = sizeof(a)-1;i>=0;--i)
{
printf("0x%02x ",p[i]);
}
putchar('\n');
}
int main()
{
// char *a = "62B1:EBBB:FE00:0306";
//
// char* b = my_inet_aton(a);
//printf("%c",b[0]);
// getchar();
// return 0;
fun(0x1234);
printf("%d\n",sizeof(0x1234));
getchar();
}
//int main(void) {
char a[4] = "abc"; // char *a = "abc"
char b[4] = "def"; // char *b = "def"
char *c = join3(a, b);
printf("Concatenated String is %s\n", c);
free(c);
c = NULL;
return 0;
// char destination[25];
// char *blank = "", *c = "C++",*Borland = "Borland";
// memset(destination, 0, 25);
// strcat(destination,Borland);
// strcat(destination,c);
// printf("%s",destination);
// getchar();
//}
//
//
#include <arpa/inet.h>
unsigned int * Extract(unsigned int x)
{
printf("%x\n",x);
static unsigned int a[3];
int i;
for(i=0;i<3;i++)
{
a[i]=x&0xff;
x = x>>8;
printf("%d\n",x);
}
return a;
}
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include<time.h>
int main()
{
//char *str="101010";
//int dex = strtol(str,NULL,16);
//printf("%d\n",strtol(str,NULL,16));
//unsigned char value[3];
//unsigned int *str1 = Extract(dex);
printf("%d",sizeof(unsigned int *));
//int a = 0x101010;
//printf("%x",a>>8);
//value[0] = str1[0];
//value[1] = str1[1];
//value[2] = str1[2];
//printf("%x\n",value[2]);
//unsigned char * NAI;
//char str[] = "nai-12345678";将nai存到一个Nai的char指针数组里
//NAI = (unsigned char *) malloc(15);
//memset(NAI,0,15);
//memcpy(NAI,&str[4],strlen(str)-4);
//printf("%s",NAI);
//free(NAI);
//printf("%d",sizeof(char));
//char* str1 = "Borland International",*str2 = "nation",*ptr;
//ptr = strstr(str1,str2);
//printf("%s",ptr);
//return 0 ;
//getchar();
getchar();
}
int inet_pton(af, src, dst)
{
int af;
const char *src;
void *dst;
switch (af) {
case AF_INET:
return (inet_pton4(src, dst));
case AF_INET6:
return (inet_pton6(src, dst));
default:
__set_errno (EAFNOSUPPORT);
return (-1);
}
/* NOTREACHED */
}
int main()
{
//unsigned int *str2 = Extract(x);
char *p = "hello";
char imsi[16];
strcpy(imsi,p+3);
for(int i = 0;i<strlen(imsi);i++)
{
printf("%c",imsi[i]);
}
getchar();
}
int main(int argc, char *argv[])
{
// //unsigned char buf[sizeof(struct in6_addr)];
// //int domain, s;
// //char str[INET6_ADDRSTRLEN];
//
// //if (argc != 3) {
// // fprintf(stderr, "Usage: %s {i4|i6|<num>} string\n", argv[0]);
// // exit(EXIT_FAILURE);
// //}
//
// //domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :
// // (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);
//
// //s = inet_pton(domain, argv[2], buf);
// //printf("%d",domain);
// //if (s <= 0) {
// // if (s == 0)
// // fprintf(stderr, "Not in presentation format");
// // else
// // perror("inet_pton");
// // exit(EXIT_FAILURE);
// //}
//
// //if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
// // perror("inet_ntop");
// // exit(EXIT_FAILURE);
// //}
//
// //printf("%s\n", str);
//
// //exit(EXIT_SUCCESS);
//
}
//#include <stdio.h>
//#include "cJSON.h"
//
//char *message =
//"{ \
// \"name\":\"mculover666\", \
// \"age\": 22, \
// \"weight\": 55.5, \
// \"address\": \
// { \
// \"country\": \"China\",\
// \"zip-code\": 111111\
// }, \
// \"skill\": [\"c\", \"Java\", \"Python\"],\
// \"student\": false \
//}";
//
//int main(void)
//{
// cJSON* cjson_test = NULL;
// cJSON* cjson_name = NULL;
// cJSON* cjson_age = NULL;
// cJSON* cjson_weight = NULL;
// cJSON* cjson_address = NULL;
// cJSON* cjson_address_country = NULL;
// cJSON* cjson_address_zipcode = NULL;
// cJSON* cjson_skill = NULL;
// cJSON* cjson_student = NULL;
// int skill_array_size = 0, i = 0;
// cJSON* cjson_skill_item = NULL;
//
// /* 解析整段JSO数据 */
// cjson_test = cJSON_Parse(message);
// if(cjson_test == NULL)
// {
// printf("parse fail.\n");
// return -1;
// }
//
// /* 依次根据名称提取JSON数据(键值对) */
// cjson_name = cJSON_GetObjectItem(cjson_test, "name");
// cjson_age = cJSON_GetObjectItem(cjson_test, "age");
// cjson_weight = cJSON_GetObjectItem(cjson_test, "weight");
//
// printf("name: %s\n", cjson_name->valuestring);
// printf("age:%d\n", cjson_age->valueint);
// printf("weight:%.1f\n", cjson_weight->valuedouble);
//
// /* 解析嵌套json数据 */
// cjson_address = cJSON_GetObjectItem(cjson_test, "address");
// cjson_address_country = cJSON_GetObjectItem(cjson_address, "country");
// cjson_address_zipcode = cJSON_GetObjectItem(cjson_address, "zip-code");
// printf("address-country:%s\naddress-zipcode:%d\n", cjson_address_country->valuestring, cjson_address_zipcode->valueint);
//
// /* 解析数组 */
// cjson_skill = cJSON_GetObjectItem(cjson_test, "skill");
// skill_array_size = cJSON_GetArraySize(cjson_skill);
// printf("skill:[");
// for(i = 0; i < skill_array_size; i++)
// {
// cjson_skill_item = cJSON_GetArrayItem(cjson_skill, i);
// printf("%s,", cjson_skill_item->valuestring);
// }
// printf("\b]\n");
//
// /* 解析布尔型数据 */
// cjson_student = cJSON_GetObjectItem(cjson_test, "student");
// if(cjson_student->valueint == 0)
// {
// printf("student: false\n");
// }
// else
// {
// printf("student:error\n");
// }
//
// return 0;
//}
【无标题】
最新推荐文章于 2024-01-18 23:25:36 发布