为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

史啦啦 的学生作业:

#include #include #include #define MAX 5 //实际学生的存储 struct student { char name[20]; int id; int age; }; typedef struct student datatype_t; typedef struct{ datatype_t buf[MAX]; //定义数组记录班级学生每个学生的信息。 int n; //学生实际到来的个数。 }seqlist_t; //为结构体在堆上分配空间,用l保存 seqlist_t *create_empty_seqlist() { seqlist_t* l = NULL; l = (seqlist_t*)malloc(sizeof(seqlist_t)); if(NULL == l) { printf("malloc is fail!\n"); return NULL; } memset(l,0,sizeof(seqlist_t)); return l; } //判断顺序表是否满了 int is_full_seqlist(seqlist_t *l) { return l->n == MAX ? 1:0; } //获取用户数据 void input_data_seqlist(datatype_t* st) { scanf("%s\t%d\t%d",st->name,&st->id,&st->age); } //插入数据 void insert_data_seqlist(seqlist_t *l,datatype_t data) { strcpy(l->buf[l->n].name,data.name); l->buf[l->n].id = data.id; l->buf[l->n].age = data.age; l->n = l->n + 1; return ; } //输出数据 void printf_data_seqlist(seqlist_t *l) { for(int i=0;in;i++) { printf("%s\t%d\t%d\n",l->buf[i].name,l->buf[i].id,l->buf[i].age); } printf("\n"); } int is_empty_seqlist(seqlist_t *l) { return l->n == 0 ? 1:0; } int delete_data_seqlist(seqlist_t *l,datatype_t data) { int i = 0,j = 0; //1.若是为空不能删除 if(is_empty_seqlist(l)) { return -1; } //2.删除对应的数据 for(i = 0;i < l->n;i++) { if(l->buf[i].id != data.id) { strcpy(l->buf[j].name,l->buf[i].name); l->buf[j].id = l->buf[i].id; l->buf[j].age = l->buf[i].age; j++; } } //更新n的值 l->n = j; //判断删除数据是否存在 if(i == j) { return -2; } else { printf("delete %d is successful!\n",data.id); } return 0; } int main() { seqlist_t* l = NULL; int ret = 0; char name[20] = {0}; l = create_empty_seqlist(); datatype_t st ; printf("please input %d number: ",MAX); while(!is_full_seqlist(l)) { input_data_seqlist(&st); insert_data_seqlist(l,st); } printf_data_seqlist(l); printf("===========================\n"); printf("please input you want to delete data : "); scanf("%d",&st.id); ret = delete_data_seqlist(l,st); if(ret < 0) { printf("seqlist is empty or data is no exist!\n"); return -1; } printf_data_seqlist(l); free(l); l = NULL; return 0; } 【图片】

得分 100
学习任务

别摸我的键盘 的学生作业:

read #include #include #include #include #include #include #define PIPE_PATH "./process_pipe" int main(int argc, const char *argv[]) { int fd = open(PIPE_PATH,O_RDONLY); if(fd == -1){ perror("[ERROR] open()"); exit(EXIT_FAILURE); } char buf[20]; int ret = read(fd, buf, sizeof(buf)); if(-1 == ret){ perror("[ERROR] read()"); exit(EXIT_FAILURE); } buf[sizeof(buf) -1] = '\0'; printf("okk! current time is %s\n", buf); close(fd); return 0; } write #include #include #include #include #include #include #include #include #define PIPE_PATH "./process_pipe" char * gettime(){ time_t cur_time; struct tm *local_tm; static char buf[20]; cur_time = time(NULL); if(cur_time == ((time_t) - 1)){ fprintf(stderr, "failed to obtain the current time.\n"); return NULL; } local_tm = localtime(&cur_time); if(local_tm == NULL){ fprintf(stderr, "failed to convert the time.\n"); return NULL; } sprintf(buf,"%04d-%02d-%02d %02d:%02d:%02d",local_tm->tm_year + 1900, local_tm->tm_mon+1, local_tm->tm_mday, local_tm->tm_hour, local_tm->tm_min, local_tm->tm_sec); return buf; } int main(int argc, const char *argv[]) { int fd; int ret = access(PIPE_PATH, F_OK); if(ret == -1){ printf("no exist mkfifo\n"); ret = mkfifo(PIPE_PATH, 0644); if(ret == -1){ perror("[ERROR] mkfifo()"); exit(EXIT_FAILURE); } } fd = open(PIPE_PATH,O_WRONLY); if(fd == -1){ perror("[ERROR] open()"); exit(EXIT_FAILURE); } char * w = gettime(); #if 1 printf("Current time is %s strlen() %d \n", w,strlen(w)); #endif ret = write(fd, w, strlen(w)); if(-1 == ret){ perror("[ERROR] write()"); exit(EXIT_FAILURE); } close(fd); return 0; }

得分 100
学习任务

史啦啦 的学生作业:

#include #include #include #define MAX 2 //实际学生的存储 struct student { char name[20]; int id; int age; }; typedef struct student datatype_t; typedef struct{ datatype_t buf[MAX]; //定义数组记录班级学生每个学生的信息。 int n; //学生实际到来的个数。 }seqlist_t; //为结构体在堆上分配空间,用l保存 seqlist_t *create_empty_seqlist() { seqlist_t* l = NULL; l = (seqlist_t*)malloc(sizeof(seqlist_t)); if(NULL == l) { printf("malloc is fail!\n"); return NULL; } memset(l,0,sizeof(seqlist_t)); return l; } //判断顺序表是否满了 int is_full_seqlist(seqlist_t *l) { return l->n == MAX ? 1:0; } //获取用户数据 void input_data_seqlist(datatype_t* st) { scanf("%s\t%d\t%d",st->name,&st->id,&st->age); } //插入数据 void insert_data_seqlist(seqlist_t *l,datatype_t data) { strcpy(l->buf[l->n].name,data.name); l->buf[l->n].id = data.id; l->buf[l->n].age = data.age; l->n = l->n + 1; return ; } //输出数据 void printf_data_seqlist(seqlist_t *l) { for(int i=0;in;i++) { printf("%s\t%d\t%d\n",l->buf[i].name,l->buf[i].id,l->buf[i].age); } printf("\n"); } int main() { seqlist_t* l = NULL; char name[20] = {0}; l = create_empty_seqlist(); datatype_t st ; printf("please input %d number: ",MAX); while(!is_full_seqlist(l)) { input_data_seqlist(&st); insert_data_seqlist(l,st); } printf_data_seqlist(l); free(l); l = NULL; return 0; } 【图片】

得分 100
学习任务
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号