File tree Expand file tree Collapse file tree 4 files changed +43
-29
lines changed
Expand file tree Collapse file tree 4 files changed +43
-29
lines changed Original file line number Diff line number Diff line change 11#include <stdio.h>
22#include <stdlib.h>
33#include <string.h>
4- void strval (char * * str1 ,const char * str2 ,int type ){
5- switch (type )
6- {
7- case 1 : {
8- * str1 = (char * )malloc (strlen (str2 + 1 ));
9- sprintf (* str1 ,"%s" ,str2 );
10- printf ("case 1 :%s\n" ,* str1 );
11- break ;
12- }
13- case 2 : {
14- * str1 = (char * )realloc (* str1 ,strlen (* str1 )+ strlen (str2 )+ 1 );
15- sprintf (* str1 ,"%s%s" ,* str1 ,str2 );
16- printf ("case 2 :%s\n" ,* str1 );
17- }
18- break ;
19- case 3 : {
20- free (* str1 );
21- * str1 = (char * )malloc (strlen (str2 + 1 ));
22- sprintf (* str1 ,"%s" ,str2 );
23- printf ("case 3 :%s\n" ,* str1 );
24- break ;
25- }
26- }
27- }
28- struct test {
4+ #include "./str.h"
5+ struct body_link {
6+ int type ;
7+ void * data ;
8+ struct body_link * next ;
9+ };
10+ struct head_link {
2911 int type [2 ];
30- char * name ;
12+ char * name ;
13+ struct body_link * head ;
14+ struct body_link * * location ;
3115 struct test * next ;
3216};
33- struct test * add (){
34- struct test * temp = (struct test * )malloc (sizeof (struct test ));
17+ struct head_link * add (){
18+ struct head_link * temp = (struct head_link * )malloc (sizeof (struct head_link ));
3519 return temp ;
3620}
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+ #include <string.h>
4+ void strval (char * * str1 ,const char * str2 ,int type );
Original file line number Diff line number Diff line change 11#include "../include/head.h"
2+ #include "../include/str.h"
23int main (){
3- struct test * test1 = add ();
4+ struct head_link * test1 = add ();
45 test1 -> type [0 ]= 1 ;
56 strval (& (test1 -> name ),"hello " ,1 );
67 strval (& (test1 -> name ),"world" ,2 );
Original file line number Diff line number Diff line change 1+ #include "../include/str.h"
2+ void strval (char * * str1 ,const char * str2 ,int type ){
3+ switch (type )
4+ {
5+ case 1 : {
6+ * str1 = (char * )malloc (strlen (str2 + 1 ));
7+ sprintf (* str1 ,"%s" ,str2 );
8+ printf ("case 1 :%s\n" ,* str1 );
9+ break ;
10+ }
11+ case 2 : {
12+ * str1 = (char * )realloc (* str1 ,strlen (* str1 )+ strlen (str2 )+ 1 );
13+ sprintf (* str1 ,"%s%s" ,* str1 ,str2 );
14+ printf ("case 2 :%s\n" ,* str1 );
15+ }
16+ break ;
17+ case 3 : {
18+ free (* str1 );
19+ * str1 = (char * )malloc (strlen (str2 + 1 ));
20+ sprintf (* str1 ,"%s" ,str2 );
21+ printf ("case 3 :%s\n" ,* str1 );
22+ break ;
23+ }
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments