''DepPrd:$#Iden1:N$#Abst:$#NumOfDys:0$#FSubCode1:$#AgntCtfTp:$#Ccy:CNY$#Wher:00$#CtfNum2:632823195205100014$#CtfTp :01$#AmtOfMny:400000.00$#CtfNum:$#Flg5:0$#CtfNum3:632823195205100014$#AgntIdNum:$#CodeC:5050$#ChkAgtName:$#AhrName:CNY$#BalA:0$#Cani:CNY$ #AcNum:81020000020245126$#Cgy2C:0112$#Cyce2C:$#IdentTp:01$#Code3C:$#AmtOfMny4:0$#Name1:哇保$#Tp6:01$#Cyce:$#BnkAc:0$#Tp1 :1121$#AgntTel:$#Name:$#AcNum1:$#Attr4:029$#IdentTp1:$#DocTp:$#SerialNum5:$#Code4C:$#DebugQueue:$#CZ_JRNL_NO_1:''用$#切割之后变成键值对
时间: 2023-09-13 21:10:24 浏览: 207
好的,根据您的要求,我将字符串用$#分割成多个键值对:
- DepPrd:
- Iden1: N
- Abst:
- NumOfDys: 0
- FSubCode1:
- AgntCtfTp:
- Ccy: CNY
- Wher: 00
- CtfNum2: 632823195205100014
- CtfTp: 01
- AmtOfMny: 400000.00
- CtfNum:
- Flg5: 0
- CtfNum3: 632823195205100014
- AgntIdNum:
- CodeC: 5050
- ChkAgtName:
- AhrName: CNY
- BalA: 0
- Cani: CNY
- AcNum: 81020000020245126
- Cgy2C: 0112
- Cyce2C:
- IdentTp: 01
- Code3C:
- AmtOfMny4: 0
- Name1: 哇保
- Tp6: 01
- Cyce:
- BnkAc: 0
- Tp1: 1121
- AgntTel:
- Name:
- AcNum1:
- Attr4: 029
- IdentTp1:
- DocTp:
- SerialNum5:
- Code4C:
- DebugQueue:
- CZ_JRNL_NO_1:
相关问题
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<windows.h> #include<string.h> #include<stdlib.h> #include<math.h> typedef struct character_name { char name[100]; struct character_name* next; }char_name; typedef struct character_title { char title[100]; struct character_title* next; }char_title; typedef struct character_identity { char identity[100]; struct character_identity* next; }char_iden; typedef struct character_profession { char profession[100]; int level; struct character_profession* next; }char_pro; typedef struct character_ability { char ability[100]; char explain[1000]; struct character_ability* next; }char_abi; typedef struct character_race { char race[100]; struct character_race* next; }char_race; typedef struct character_information { int age; int gender; char_name* _name; char_title* _title; char_iden* _iden; char_pro* _pro; char_abi* _abi; char_race* _race; struct character_information* next; }char_inf; char_inf* initialization() { char_inf* node = (char_inf*)malloc(sizeof(char_inf)); node->_name = (char_name*)malloc(sizeof(char_name)); node->_title = (char_title*)malloc(sizeof(char_title)); node->_iden = (char_iden*)malloc(sizeof(char_iden)); node->_pro = (char_pro*)malloc(sizeof(char_pro)); node->_abi = (char_abi*)malloc(sizeof(char_abi)); node->_race = (char_race*)malloc(sizeof(char_race)); return node; } char_inf* ceshi, * current, * end; char_name* name_current, * name_end; char_title* title_current, * title_end; char_iden* iden_current, * iden_end; char_pro* pro_current, * pro_end; char_abi* abi_current, * abi_end; char_race* race_current, * race_end; int main() { ceshi = initialization(); ceshi->age = 666; ceshi->gender = 1; name_current = ceshi->_name; strcpy(name_current->name, "ceshi_name_1"); name_current->next = (char_name*)malloc(sizeof(char_name)); name_current = name_current->next; name_current->next = NULL; strcpy(name_current->name, "ceshi_name_2"); strcpy(ceshi->_title->title, "ceshi_title"); strcpy(ceshi->_iden->identity, "ceshi_identity"); strcpy(ceshi->_pro->profession, "ceshi_profession"); strcpy(ceshi->_abi->ability, "ceshi_ability"); strcpy(ceshi->_abi->explain, "ceshi_ability_explain"); strcpy(ceshi->_race->race, "ceshi_race"); ceshi->_pro->level = 666; name_current = ceshi->_name; printf(" Age: %d\n", ceshi->age); printf(" Gender: "); if (ceshi->gender == 0) printf("woman\n"); else printf("male\n"); while (name_current != NULL) { printf(" Name: %s\n", name_current->name); name_current = name_current->next; } printf(" Title: %s\n Identity: %s\n Profession: %d\n Ability: %s\n Ability_Explain: %s\n Race: %s\n", ceshi->_title->title, ceshi->_iden->identity,ceshi->_pro->level,ceshi->_abi->ability,ceshi->_abi->explain,ceshi->_race->race); return 0; } 怎样可以消除取消对NULL指针的引用这个警告
要消除对NULL指针的引用警告,你可以使用以下方法:
1. 在编译时使用特定的编译选项或指令。例如,对于gcc编译器,你可以使用`-Wno-null-dereference`选项来禁用对NULL指针引用的警告。
```bash
gcc -Wno-null-dereference your_code.c
```
2. 使用编译指令来取消警告。在代码中,你可以使用特定的编译指令来取消对NULL指针引用的警告。在C语言中,你可以使用`#pragma`指令来实现。例如:
```c
#pragma GCC diagnostic ignored "-Wnull-dereference"
// 在这里写你的代码
#pragma GCC diagnostic warning "-Wnull-dereference"
```
这将在特定代码块中取消和重新启用对NULL指针引用的警告。
3. 针对特定行的警告,你可以使用条件语句来避免对NULL指针进行操作。例如,使用`if`语句检查指针是否为空。
```c
if (pointer != NULL) {
// 在这里进行指针操作
}
```
请注意,取消对NULL指针引用的警告可能会隐藏真正的问题,因此请谨慎使用此功能,并确保你了解代码中的潜在问题。
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<windows.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<malloc.h> typedef struct character_name { char name[100]; struct character_name* next; }char_name; typedef struct character_title { char title[100]; struct character_title* next; }char_title; typedef struct character_identity { char identity[100]; struct character_identity* next; }char_iden; typedef struct character_attribute { int strength; struct character_attribute* next; }char_att; typedef struct character_information { char_name* _name; char_title* _title; char_iden* _iden; char_att* _att; struct character_information* next; }char_inf; char_inf* initialization() { char_inf* node = (char_inf*)malloc(sizeof(char_inf)); node->_name = (char_name*)malloc(sizeof(char_name)); node->_title = (char_title*)malloc(sizeof(char_title)); node->_iden = (char_iden*)malloc(sizeof(char_iden)); node->_att = (char_att*)malloc(sizeof(char_att)); return node; } char_inf* ceshi, * current, * end; char_name* name_current, * name_end; char_title* title_current, * title_end; char_iden* iden_current, * iden_end; char_att* att_current, att_end; int main() { ceshi = initialization(); name_current = (char_name*)malloc(sizeof(char_name)); name_current = ceshi->_name; strcpy(name_current->name, "ceshi_1_1"); name_current->next = (char_name*)malloc(sizeof(char_name)); name_current = name_current->next; strcpy(name_current->name, "ceshi_1_2"); strcpy(ceshi->_title->title, "ceshi_2"); strcpy(ceshi->_iden->identity, "ceshi_3"); ceshi->_att->strength = 4; name_current = ceshi->_name; while (name_current->next != NULL) { printf("%s\n", name_current->name); name_current = name_current->next; } printf("%s\n%s\n%d\n", ceshi->_title->title, ceshi->_iden->identity, ceshi->_att->strength); return 0; } 中为什么在下面两段代码中报错 name_current = (char_name*)malloc(sizeof(char_name)); name_current = ceshi->_name; strcpy(name_current->name, "ceshi_1_1"); name_current->next = (char_name*)malloc(sizeof(char_name)); name_current = name_current->next; strcpy(name_current->name, "ceshi_1_2"); name_current = ceshi->_name; while (name_current->next != NULL) { printf("%s\n", name_current->name); name_current = name_current->next; }
在下面两段代码中报错的原因是你没有正确地为name_current分配内存空间。
首先,在这行代码中:
```c
name_current = (char_name*)malloc(sizeof(char_name));
```
你为name_current分配了内存空间,但是在接下来的一行代码中:
```c
name_current = ceshi->_name;
```
你又将name_current指向了ceshi->_name,这导致你刚刚分配的内存空间被覆盖了,造成内存泄漏。
解决这个问题的方法是,你可以直接将ceshi->_name赋给name_current,而不需要使用malloc来为name_current分配内存空间,修改后的代码如下:
```c
name_current = ceshi->_name;
strcpy(name_current->name, "ceshi_1_1");
name_current->next = (char_name*)malloc(sizeof(char_name));
name_current = name_current->next;
strcpy(name_current->name, "ceshi_1_2");
```
另外,在最后一段代码中,你需要检查name_current是否为NULL,否则可能会出现访问空指针的错误。修改后的代码如下:
```c
name_current = ceshi->_name;
while (name_current != NULL)
{
printf("%s\n", name_current->name);
name_current = name_current->next;
}
```
阅读全文