C language serial port transmission structure

Serial port transmission structure is to convert the structure into an array, and then transfer the char in the array.

That is struct——->> char [] ;

Then char[]———>> struct.

Give a simple example code:

#include #include #include struct data{ int id; int score; char name[10];}; #define SIZE sizeof(struct data)void struct_array(char* des, struct data *src){ int num; char *temp = (char *)src; for(num=0; numid=1; shm->score=98; strcpy(shm->name, "admin"); char buf[SIZE]={"" }; struct data *str = (struct data *)malloc(SIZE); struct_array(buf, shm); show_array(buf, SIZE); array_struct(str, buf); printf("%d
%d
% s
", str->id, str->score, str->name); free(shm); free( str); return 0;} 

  

Run result:

share picture

#include #include < string.h>#include struct data{ int id; int score; char name[10];}; #define SIZE sizeof(struct data)void struct_array(char* des, struct data *src){ int num; char *temp = (char *)src; for(num=0; numid=1; shm->score=98; strcpy(shm->name, "admin"); char buf[SIZE]={""} ; struct data *str = (struct data *)malloc(SIZE); struct_array(buf, shm); show_array(buf, SIZE); array_struct(str, buf); printf("%d
%d
%s
", str->id, str->score, str->name); free(shm); free( str); return 0;} 

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1221 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.