printf数据丢失-------------

int main()
{
char a[2],b[2];

          strcpy(a,"00");
        strcpy(b,"00");             
    printf("%s------%s\n",a,b); 

            return 0;

}

输出结果:------00

求解,a的值哪去了?

2个回答

 字符串需要一个结束字符,所以长度为2的字符串只能装最多一个字符。
这段代码中,strcpy(b, "00");实际上往b写入了3个字符,'0''0''\0',而'\0侵占了a(这一点不一定在所有的编译器上成立,只是针对你的编译器是在堆栈上存放a、b,堆栈向下扩展,在你的编译器上,a紧贴b,所以a在b地址后面),实际上它存在a[0]上了。
这导致printf输出a的时候,第一个字符就是'\0',所以什么都没有输出。

要想正确输出,需要修改
char a[2],b[2];

char a[3],b[3];

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
利用结构体数组插入删除数据
请问插入和删除最后输出的那一段的代码怎么写?拜托啦,急求!!! #include<stdio.h> #include<string.h> struct Student { int num; char name[20]; int score; struct Student*next; }; int main() { struct Student stu[10]={{10101,"Zhao",89},{10102,"Qian" ,90},{10103,"Sun",93},{10104,"Li",94}, {10105,"Zhou",95},{10106,"Wu",96},{10107,"Zheng",97},{10108,"Wang",98},{10109,"Feng",99},{10110,"Cheng",100}}; int i; printf(" 学号 姓名 成绩\n"); for(i=0;i<10;i++) printf("%7d%8s%6d\n",stu[i].num,stu[i].name,stu[i].score); printf(" ---要插入的数据---\n"); printf(" 学号 姓名 成绩\n"); printf(" ---要删除的数据---\n"); printf(" 学号 姓名 成绩\n"); return 0; } 又新写的,但是插入后原来位置的数据丢失,请问该怎么改?谢谢! #include<stdio.h> #include<string.h> struct Student { int num; char name[20]; int score; struct Student*next; }; int main() { struct Student stu[20]={{10101,"Zhao",89},{10102,"Qian" ,90},{10103,"Sun",93},{10104,"Li",94}, {10105,"Zhou",95},{10106,"Wu",96},{10107,"Zheng",97},{10108,"Wang",98},{10109,"Feng",99},{10110,"Cheng",100}}; int i; printf(" 学号 姓名 成绩\n"); for(i=0;i<10;i++) printf("%7d%8s%6d\n",stu[i].num,stu[i].name,stu[i].score); printf(" ---要插入的数据下标---\n"); int a; scanf("%d",&a); stu[a].num=10113; strcpy(stu[a].name ,"Chu"); stu[a].score =98; if(i==a) { stu[i+1]=stu[i]; stu[i]=stu[a]; } printf(" 学号 姓名 成绩\n"); for(i=0;i<11;i++) printf("%7d%8s%6d\n",stu[i].num,stu[i].name,stu[i].score); printf(" ---要删除的数据下标---\n"); int x; scanf("%d",&x); for(i=x;i<10;i++) stu[i]=stu[i+1]; printf(" 学号 姓名 成绩\n"); for(i=0;i<9;i++) printf("%7d%8s%6d\n",stu[i].num,stu[i].name,stu[i].score); return 0; }
求改正,不知道为什么导不出文件
#include <stdio.h> #include <stdlib.h> #include <io.h> #include <ctype.h> #include <string.h> #include <conio.h> #include <sys/stat.h> typedef struct student { char name[10]; int schoolnumber; int classnumber; float score[10]; struct student *next; } stu,*stupt; stupt st=NULL;//学生信息的头指针 stupt qt=NULL;//学生信息的尾指针 FILE* fp;//文件指针 typedef struct user { char logname[10]; char passwd[6]; }*userpt,user; void clear(void)//清空缓冲区函数 { char ch; do { ch=getchar(); } while(ch!='\n'); } void Printf_help()//主菜单 { printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(" |*尊敬的用户请您选择操作: *|\n"); printf(" |* 1.手动输入学生作业的分数 *|\n"); printf(" |* 2.从文件导入学生信息 *|\n"); printf(" |* 3.输入学号,显示某位学生作业完成情况 *|\n"); printf(" |* 4.输入班级的班号,显示该班所有学生的作业完成情况 *|\n"); printf(" |* 5.输入学生的学号,修改该学生的各类信息 *|\n"); printf(" |* 6.输入学生的学号,删除该学生的信息 *|\n"); printf(" |* 7.显示各类统计信息 *|\n"); printf(" |* 8.菜单 *|\n"); printf(" |* 9.清屏 *|\n"); printf(" |* a.导出至文件 *|\n"); printf(" |* 0.退出系统 *|\n"); printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(":"); } //1.输入成绩 void inpu(stupt p) { int n; int m=0; int flag; while(m<10)//成绩初始化为0 { p->score[m]=0; m++; } printf("请您输入姓名:"); scanf("%s",p->name); clear(); printf("请您输入学号:"); scanf("%d",&p->schoolnumber); clear(); printf("请您输入班级号(如:101):"); scanf("%d",&p->classnumber); clear(); do { printf("请您输入第几次作业(1~10):"); scanf("%d",&n); clear(); printf("请您输入该次作业成绩:"); scanf("%f",&p->score[n-1]); clear();//清空缓冲区 printf("您是否继续输入该生成绩,退出请按q,其他键继续:"); flag=getchar(); clear();//清空缓冲区堆积 } while(flag!='q'); } void input(stupt st,stupt qt) { char flag; stupt p,q; p=q=NULL; printf("请问您确认输入?y.是 n.取消(注意大小写)\n"); while((flag=getchar())!='n') { clear();//清空缓冲区 if(flag=='y') { p=(stupt)malloc(sizeof(st));//动态申请空间 if(p==NULL) exit(1); inpu(p); if(st==NULL) st=qt=p; else if(qt!=NULL) { qt->next=p; //尾指针非空(及链表已存在)接着尾指针建立链表 qt=p; } } else { printf("温馨提示:您存在非法输入,请进入菜单界面重新选择(按8或9):"); return; } printf("请问您是否继续输入?y.是 n.否(注意大小写)\n"); } if(flag=='n') { Printf_help(); clear(); } if(p!=NULL&&qt!=NULL) { qt->next=NULL; } } //2.导入成绩、 void read1(stupt p,FILE* fp) { fscanf(fp,"%s",&p->name); fscanf(fp,"%d",&p->schoolnumber); fscanf(fp,"%d",&p->classnumber); fscanf(fp,"%f",&p->score[0]); fscanf(fp,"%f",&p->score[1]); fscanf(fp,"%f",&p->score[2]); fscanf(fp,"%f",&p->score[3]); fscanf(fp,"%f",&p->score[4]); fscanf(fp,"%f",&p->score[5]); fscanf(fp,"%f",&p->score[6]); fscanf(fp,"%f",&p->score[7]); fscanf(fp,"%f",&p->score[8]); fscanf(fp,"%f",&p->score[9]); } //从文件导入数据 void filep_read_to_st(stupt st,FILE* fp) { stupt p; st=NULL;//置空st,准备从文件中导入学生信息 while(1) { p=(stupt)malloc(sizeof(stu)); read1(p,fp); if(feof(fp)) //如果文件结束,则结束(feof:检测流上的文件结束符) break; if(st==NULL) st=qt=p; else if(qt!=NULL) { qt->next=p; //尾指针非空(即链表已存在)接着尾指针建立链表 qt=p; } } if(feof(fp)) { qt->next=NULL; //如果文件结束,尾指针next指空 } if(st!=NULL&&feof(fp)) printf("温馨提示:您的文件导入成功!\n"); else printf("温馨提示:您的文件导入失败,请重新导入!\n"); } void readfile(stupt st,FILE* fp)//写入数据方式 { char flag,flag_1; char filename[90]; printf("温馨提示:您如果在导入前有过手动输入,请先导出至文件后再进行导入,否则输入那部分数据将丢失。\n"); printf("按任意键继续,退出请按q:"); flag_1=getchar(); clear(); if(flag_1=='q') { return; } printf("程序默认路径导入:"); clear(); fp=fopen("student_homework_infor.txt","r"); if(access("student_homework_infor.txt",0)==1) { printf("温馨提示:您的文件不存在!\n"); } if(fp==NULL) { printf("温馨提示:打开程序所在目录下的student_homework_infor.txt文件失败,请返回主菜单重试!\n"); return; } else filep_read_to_st(st,fp); fclose(fp); } //3.按学号查询 void printf_score(stupt p)//输出该学号学生的成绩 { int n=0; printf("前十次成绩如下:\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); while(n<10) { printf("%f ",p->score[n]); n++; } printf("\n"); } void search(stupt st,int snum)//判断学号是否合法 { stupt p,q; if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } else { p=st; q=p->next; } if(p->schoolnumber==snum) { printf_score(p); //查找成功输出并返回上级函数 return; } while(q!=NULL) { if(q->schoolnumber==snum) { printf_score(q); //查找成功输出并返回上级函数 return; } q=q->next;//下一个 } printf("查询失败,该学号学生信息不存在\n"); } void school_num_search(stupt st) { int snum; char flag; do { printf("请输入要查找的学生学号(如221):"); scanf("%d",&snum); clear();//清空scanf结束时进入缓冲的enter符 search(st,snum); printf("退出请按q,其它任意键继续查找:"); flag=getchar(); clear();//清空回车符 } while(flag!='q'); if(flag=='q') { Printf_help(); } } //4.给定班级查询 void printf_infor(stupt p) //输出函数 { printf("%-5d%-8s%-5d%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f%-6.1f\n",p->classnumber,p->name,p->schoolnumber,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5],p->score[5],p->score[7],p->score[8],p->score[9]); printf("──────────────────────────────────────\n"); } void search_2(stupt st,int clnum) { stupt p,q; int f=0; if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入所有学生的信息\n"); return; } else { p=st; q=p->next; } printf("班级 姓名 学号 成绩1 成绩2 成绩3 成绩4 成绩5 成绩6 成绩7 成绩8 成绩9 成绩10\n"); printf("──────────────────────────────────────\n"); if(p->classnumber==clnum) { printf_infor(p); f++; }//查找成功输出 while(q!=NULL) { if(q->classnumber==clnum) { printf_infor(q); f++; }//查找成功输出 q=q->next;//下一个 } if(f==0) { printf("没有该班级学生信息\n"); } } void class_num_search(stupt st)//查找班级 { int clnum; char flag; do { printf("请输入班级(如101):"); scanf("%d",&clnum); clear();//清空scanf结束时进入缓冲的enter符 search_2(st,clnum); printf("退出请按q,其它任意键继续查找:"); flag=getchar(); clear();//清空回车符 } while(flag!='q'); if(flag=='q') { Printf_help(); } } //5.修改姓名班级成绩 void change_name(stupt p)//修改姓名 { printf("原姓名为:%s\n",p->name); printf("请输入新姓名:"); scanf("%s",p->name); clear(); } void change_class(stupt p)//修改班级 { printf("原班级为:%d\n",p->classnumber); printf("请输入新班级:"); scanf("%d",&p->classnumber); clear(); } void change_score(stupt p)//修改分数 { int n; char flag; do { printf("请输入:要修改的作业的次数(1~10):"); scanf("%d",&n); clear();//清空缓冲区 printf("原成绩为:%f\n",p->score[n-1]); printf("请输入:该次作业新成绩:"); scanf("%f",&p->score[n-1]); clear();//清空缓冲区 printf("是否继续修改该生成绩,退出请按q,其他键继续"); flag=getchar(); clear(); } while(flag!='q'); } void printf_help_2()//帮助列表 { printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(" |* 请选择操作: *|\n"); printf(" |* 1.修改姓名 *|\n"); printf(" |* 2.修改班级 *|\n"); printf(" |* 3.修改成绩 *|\n"); printf(" |* 0.返回 *|\n"); printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(":"); } void change(stupt p) { char a; printf_help_2(); while((a=getchar())!='0') { clear(); printf("班级 姓名 学号 成绩1 成绩2 成绩3 成绩4 成绩5 成绩6 成绩7 成绩8 成绩9 成绩10\n"); printf("──────────────────────────────────────\n"); printf_infor(p); switch(a) { case '1': { printf("您选择了:1.修改姓名\n"); change_name(p); break; } case '2': { printf("您选择了:2.修改班级\n"); change_class(p); break; } case '3': { printf("您选择了:3.修改成绩\n"); change_score(p); break; } default: { printf("非法输入,请重新选择!\n"); break; } } printf_help_2(); } if(a=='0') { clear(); printf("您选择了:0.返回\n"); } } void search_3(stupt st,int snum) { stupt p,q; int f=0; if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } else { p=st; q=p->next; } if(p->schoolnumber==snum) { change(p); //查找成功并修改 f++; return; } while(q!=NULL) { if(q->schoolnumber==snum) { change(q); //查找成功并修改 return; } q=q->next;//下一个 } if(f==0) { printf("没有该学生信息\n"); } } void school_num_change(stupt st) { int snum; char flag; do { printf("请输入要修改学生学号(如101):"); scanf("%d",&snum); clear();//清空scanf结束时进入缓冲的enter符 search_3(st,snum); printf("退出请按q,其它任意键继续按学号查找修改信息:"); flag=getchar(); clear();//清空回车符 } while(flag!='q'); if(flag=='q') { Printf_help(); } } //6.删除学生信息 void delete_pt(stupt st,int snum)//判断并删除 { stupt p,q; if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } else { p=st; q=p->next; } if(p->schoolnumber==snum)//按照学号删除 { st=q; //查找成功删除并返回上级函数 printf("班级 姓名 学号 成绩1 成绩2 成绩3 成绩4 成绩5 成绩6 成绩7 成绩8 成绩9 成绩10\n"); printf("──────────────────────────────────────\n"); printf_infor(p); free(p); printf("上面信息删除成功!\n"); return; } while(q!=NULL) { if(q->schoolnumber==snum) { p->next=q->next; //查找成功删除并返回上级函数 printf("班级 姓名 学号 成绩1 成绩2 成绩3 成绩4 成绩5 成绩6 成绩7 成绩8 成绩9 成绩10\n"); printf("──────────────────────────────────────\n"); printf_infor(q); free(q); printf("上面信息删除成功!\n"); return; } else//下一个 { p=q; q=p->next; } } printf("删除失败,该学号学生信息不存在\n"); } void school_num_delete(stupt st) { int snum; char flag; do { printf("请输入要删除的学生学号(如221):"); scanf("%d",&snum); clear();//清空scanf结束时进入缓冲的enter符 delete_pt(st,snum); printf("返回请按q,其它任意键继续删除:"); flag=getchar(); clear();//清空回车符 } while(flag!='q'); if(flag=='q') { Printf_help(); } } //7.查询成绩,按学号班级,降序 void printf_help_3()//帮助菜单 { printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(" |*请选择操作: *|\n"); printf(" |* 1.按学号查看学生平均成绩 *|\n"); printf(" |* 2.按班级查看学生平均成绩 *|\n"); printf(" |* 3.按平均成绩降序排序(操作执行后将会对学生信息排序 )*|\n"); printf(" |* 0.返回主菜单 *|\n"); printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(":"); } int aver(stupt p)//平均成绩 { int n=0; float sum=0;//和初始化为0 while(n<10) { sum+=p->score[n]; n++; } return sum; } void search_4(stupt st,int snum) { stupt p,q; int f=0; int sum; printf("-----------------------------------------------------------------------------\n");//分行符 if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } else { p=st; q=p->next; } if(p->schoolnumber==snum) { sum=aver(p); printf("姓名:%-10s学号:%-10d班级:%-10d作业完成平均成绩:%d\n",p->name,p->schoolnumber,p->classnumber,sum/10); f++; printf("-----------------------------------------------------------------------------\n");//分行符 return; }//查找成功并输出平均值 while(q!=NULL) { if(q->schoolnumber==snum) { sum=aver(q); printf("姓名:%-10s学号:%-10d班级:%-10d作业完成平均成绩:%d\n",q->name,q->schoolnumber,q->classnumber,sum/10); f++; printf("-----------------------------------------------------------------------------\n");//分行符 return; }//查找成功并输出平均值 q=q->next;//下一个 } if(f==0) { printf("没有该学生信息\n"); } } void snum_check_aver(stupt st)//按学号输出学生平均成绩 { int snum; printf("请输入学号:"); scanf("%d",&snum); clear();//清空scanf结束时进入缓冲的enter符 search_4(st,snum); } void search_5(stupt st,int cnum) { stupt p,q; int f=0; int sum; printf("-----------------------------------------------------------------------------\n");//分行符 if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } else { p=st; q=p->next; } if(p->classnumber==cnum) { sum=aver(p); printf("姓名:%-10s学号:%-10d班级:%-10d作业完成平均成绩:%d\n",p->name,p->schoolnumber,p->classnumber,sum/10); f++; }//查找成功并输出平均值 while(q!=NULL) { if(q->classnumber==cnum) { sum=aver(q); printf("姓名:%-10s学号:%-10d班级:%-10d作业完成平均成绩:%d\n",q->name,q->schoolnumber,q->classnumber,sum/10); f++; }//查找成功并输出平均值 q=q->next;//下一个 } if(f==0) { printf("没有该班级的信息\n"); } printf("-----------------------------------------------------------------------------\n");//分行 } void cnum_check_aver(stupt st) { int cnum; printf("请输入班级:"); scanf("%d",&cnum); clear();//清空scanf结束时进入缓冲的enter符 search_5(st,cnum); } void insert_emp1(stupt emp1,stupt q) { stupt pt1,pt2; pt1=emp1; pt2=pt1->next; while(pt2!=NULL) { if(aver(q)>aver(pt2))//插到pt2之前 { pt1->next=q; q->next=pt2; return; } else//指针后移 { pt1=pt2; pt2=pt1->next; } } pt1->next=q;//比所有的都不大,插到末尾 q->next=NULL; } void descending_order_check(stupt st) { stupt emp1,head1,head2,pt; float sum; printf("-----------------------------------------------------------------------------\n");//分行符 if(st==NULL) { printf("未建立学生信息表,请返回主菜单输入或导入所有学生的信息\n"); return; } head1=(stupt)malloc(sizeof(stu)); head2=(stupt)malloc(sizeof(stu));//另一个空链表头指针,将st有序插入到head2 head1->next=st->next; st->next=NULL; head2->next=st; pt=head1->next; while(pt!=NULL) { head1->next=pt->next; insert_emp1(head2,pt); pt=head1->next; } emp1=head2->next; st=emp1; while(emp1!=NULL) { sum=aver(emp1); printf("姓名:%-10s学号:%-10d班级:%-10d作业完成平均成绩:%-10.3f\n",emp1->name,emp1->schoolnumber,emp1->classnumber,sum/10); emp1=emp1->next; } printf("-----------------------------------------------------------------------------\n");//分行符 } //----------------------------------------------------------------------------------------------- void statistics_result(stupt st) { char flag; printf_help_3(); while((flag=getchar())!='0') { clear(); switch(flag) { case '1': { printf("您选择了:1.按学号查看学生平均成绩\n"); snum_check_aver(st); break; } case '2': { printf("您选择了:2.按班级查看学生平均成绩\n"); cnum_check_aver(st); break; } case '3': { printf("您选择了:3.查看学生平均成绩降序序列\n"); descending_order_check(st); break; } default: { printf("非法输入,请重新选择!\n"); clear(); break; } } printf_help_3(); } if(flag=='0') { printf("您选择了:0.返回主菜单\n"); clear(); Printf_help(); } } //导出 void fileprintf(stupt st,FILE* fp) { stupt pt; pt=st; while(pt!=NULL) { fprintf(fp,"%s %d %d %f %f %f %f %f %f %f %f %f %f\n",pt->name,pt->schoolnumber,pt->classnumber,pt->score[0],pt->score[1],pt->score[2],pt->score[3],pt->score[4],pt->score[5],pt->score[6],pt->score[7],pt->score[8],pt->score[9]); pt=pt->next; } printf("文件导出成功 !\n"); } void creat_files(stupt st,FILE* fp) { char flag; char filename[90]; printf("默认路径保存(为当前目录下的student_homework_infor.txt)"); clear(); fp=fopen(".\\student_homework_infor.txt","a"); if(fp==NULL) { printf("创建文件至程序所在目录下的student_homework_infor.txt文件失败,请返回主菜单重试!"); return; } else fileprintf(st,fp); fclose(fp); } //注册登录 void printf_log() { printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf("\t\t\t|* 请选择操作: *|\n"); printf("\t\t\t|* 1.登录 *|\n"); printf("\t\t\t|* 2.注册 *|\n"); printf("\t\t\t|* 0.退出 *|\n"); printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ \n"); printf(":"); } void write_in_file(char *a,char *name,FILE *fp) { fprintf(fp,"%s %s\n",a,name); fclose(fp); printf("您已注册成功!\n"); } void read_passwd(char *a,char *name,FILE *fp) { fscanf(fp,"%s",a); fscanf(fp,"%s",name); } int log() { char ch; char a[7]={'0'}; char name[12]={'0'};//初始化 char b[7]={'0'}; FILE* fp; int i; fp=fopen("passwd.txt","r"); if(fp==NULL) { printf("注册文件无法打开,请在程序当前目录下创建passwd.txt文件并重新注册!\n"); exit(1); } ch=getc(fp); if(ch==EOF) { printf("未注册,请注册!\n"); return 1; } fclose(fp); fp=fopen("passwd.txt","r"); if(fp==NULL) { fp=fopen("passwd.txt","a"); exit(1); fclose(fp); } read_passwd(a,name,fp); fclose(fp); printf("用户名:%s\n",name); printf("请输入密码:(6个字符)"); for(i=0;i<6;i++) { b[i]=getch(); printf("*"); } b[6]='\0'; clear(); if(strcmp(a,b)==0) { printf("登陆成功!\n"); return 0; } else { printf("密码错误,请重新登录\n"); return 1; } } void login() { char a[7]={'0'}; char b[7]={'0'}; char name[12]={'0'};//初始化 FILE* fp; char ch; int i; fp=fopen("passwd.txt","r"); if(fp==NULL) { printf("注册文件无法打开或已损坏,请在程序当前目录下创建passwd.txt文件!\n"); return; } ch=getc(fp); fclose(fp); if(ch!=EOF) { printf("账户已存在,请返回登陆菜单!\n"); return; } printf("请输入用户名:(小于12字符)"); scanf("%s",name); clear(); lab_3:printf("请输入密码:(6个字符)"); for(i=0;i<6;i++) { a[i]=getch(); printf("*"); } clear(); printf("请确认密码:(6个字符)"); for(i=0;i<6;i++) { b[i]=getch(); printf("*"); } clear(); if(strcmp(a,b)!=0) { printf("两次输入密码不一致,请重新输入!\n"); goto lab_3; } fp=fopen("passwd.txt","wb"); write_in_file(a,name,fp); } int user_log() { char flag; int f; do { printf_log(); flag=getchar(); clear(); if(flag=='1') { f=log(); if(f==0) { return 0; } } else if(flag=='2') { login(); } else if(flag=='0') { return 1; } else { printf("非法输入!,请重新新选择:\n"); } } while(1); } ////////////////////////////////////////////////-main-////////////////////////////////////////////////// int main() { char a,ch; printf(" ┄欢迎您使用学生作业完成情况管理程序┄ \n"); if(user_log()==1) { printf(" ┄谢谢您的使用┄ \n"); return 0; } lab_3: Printf_help(); while((a=getchar())!='0') { clear(); switch(a) { case '1': { printf("您选择了:1.手动输入学生作业的分数\n"); input(st,qt); break; } case '2': { printf("您选择了:2.从文件导入学生信息\n"); readfile(st,fp); Printf_help(); break; } case '3': { printf("您选择了:3.给定学号,显示某位学生作业完成情况\n"); school_num_search(st); break; } case '4': { printf("您选择了:4.输入班级的班号,显示该班所有学生的作业完成情况\n"); class_num_search(st); break; } case '5': { printf("您选择了:5.输入学生的学号,修改该学生的作业完成信息\n"); school_num_change(st); break; } case '6': { printf("您选择了:6.输入学生的学号,删除该学生的信息\n"); school_num_delete(st); break; } case '7': { printf("您选择了:7.显示各类统计信息\n"); statistics_result(st); break; } case '8': { printf("您选择了:8.菜单\n"); Printf_help(); break; } case '9': { printf("您选择了:9.清屏\n"); system("CLS"); Printf_help(); break; } case 'a': { printf("您选择了:a.导出文件\n"); creat_files(st,fp); Printf_help(); break; } default: { printf("非法输入,请重新选择!\n"); Printf_help(); break; } } } if(a=='0') { printf("您选择了:0.退出系统\n"); printf("退出系统时需要导出文件,否则之前操作无效!\n"); printf("按q返回,其它任意键继续\n"); clear(); if((ch=getchar())=='q') { clear(); goto lab_3; } printf(" ┄谢谢使用┄ \n"); } return 0; }
小白 提问 将小数全化成整数 如123.456变成123456数据有部分丢失怎么解决
#include int main() { double a; scanf("%lf",&a); while(a-int(a)>1e-6) a=a*10; printf("%lf",a); } 代码 但是有的数字如12.456时候可以 有的数字如123.456不行,应该是数据丢失了 但是怎么该?
小白 将一个数字中的偶数提出来组成新的数包括小数部分,小数部分数据丢失怎么解决
#include<stdio.h> int main() { double a,c; int b,d=0,e=1; scanf("%lf",&a); b=int(a); c=a-b; while(b!=0) { if(b%2==0) { d=d+b%10*e; e=e*10; } b=b/10; } if(d==0) printf("整数部分无偶数"); else printf("%d",d); printf("."); while(c-int(c)>1e-6) { c=c*10; if(c<1) printf("0"); } b=int(c); d=0; e=1; while(b!=0) { if(b%2==0) { d=d+b%10*e; e=e*10; } b=b/10; } if(d==0) printf("小数部分无偶数"); else printf("%d",d); } 我的代码 但是有的带小数的会数据丢失出不来循环 求大神改下
菜鸡求教,本人用stm32f103做串口通讯实验,接收时出现数据丢失。
任务是用stm32f103向一块超声波模块发送一个16进制指令 内容为55 aa 01 01 01 01 模块返回一个55 aa 01 01 xx xx xx的数据(xx为测量数据) 结果是串口监视串口显示打印接收到的数据只有55 aa(本应该是55 aa 01 01 xx xx xx的数据) ![图片说明](https://img-ask.csdn.net/upload/201912/18/1576657506_250765.png) 经过检查模块确实发送了7个16进制数回来,但为啥单片机只收到两个呢? 跪求大佬帮忙! 具体代码为 ``` u8 rece[100]; u16 dist=0; u8 relen=0; int main(void) { u8 t=0; u8 send[6]; u8 len=sizeof(send); send[0]=0x55; send[1]=0xaa; send[2]=0x01; send[3]=0x01; send[4]=0x01; send[5]=0x01; delay_init(); LED_Init(); KEY_Init(); BEEP_Init(); uart_init1(9600); uart_init2(9600); TIM3_PWM_Init(7199,9); TIM_SetCompare2(TIM3,4700); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); while(1){ for(t=0;t<len;t++){ USART_SendData(USART1,send[t]); while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET); } LED0=0; LED1=1; delay_ms(1000); //printf("\r\ndist=%d \r\n",dist); } } void USART1_IRQHandler(void){ u8 res; if(USART_GetITStatus(USART1,USART_IT_RXNE)){ res= USART_ReceiveData(USART1); printf("\r\nres=%x ",res); } } ```
vc6输出框输出书库丢失问题
#include<stdio.h> void main() { int year,leap; for(year=2000;year<=2500;year++) { if( year%4==0&&year%100!=0) { leap=1; printf("%d是闰年\n",year);//_每个printf后面是用的换行符\n。占用行数很多_ } else if(year%400==0) { printf("%d是闰年\n",year);//导致运行结果,2200年以前的闰年数据,没有输出 } else { leap=0; printf("%d不是闰年\n",year); } } }
UDP通信中服务端接受数据计算数据包个数
UDP通信中客户端通过多线程发送数据,服务端单线程接受数据,出现的“丢包”(我在服务端计算出来的包个数)现象很严重,通过wireshark抓包发现没有任何数据包丢失,菜鸟求解答。代码如下: /*基于LINUX的udp的通信,服务器端*/ #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> char buf[1024 * 32] = {0}; int main(int argc, char *argv[]) { if (argc < 2) { printf("Please Input Recv Port\n"); return 1; } int sockfd = 0; int recv_num = 0; int recv_count = 0; int client_len = 0; volatile unsigned long res = 0;//接收数据的总大小 int len_recv_buffer = 1024 * 32; FILE *fp; char buffer[1024*320] = {0}; struct sockaddr_in addr; //1、创建socket sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { printf("Create Socket Error\n"); return -1; } //2、准备地址 addr.sin_family = AF_INET; addr.sin_port = htons(atoi(argv[1])); addr.sin_addr.s_addr = inet_addr("192.168.17.95"); client_len = sizeof(struct sockaddr_in); //3、绑定 if (bind(sockfd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) == -1) { printf("Bind Error\n"); return 0; } //4、接收客户端发送来的数据 time_t t_old = time(NULL); time_t t_now = t_old; time_t _old = time(NULL); time_t _now = 0; time_t _interval = 0; if ((fp = fopen("recv.txt", "a+")) == NULL) { printf("Open File Error\n"); return 1; } int nRecv = 0; setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (const char*)&nRecv, sizeof(nRecv)); while(1) { memset(buf, 0 , sizeof(buf)); recv_num = recvfrom(sockfd, buf, sizeof(buf), MSG_CTRUNC, (struct sockaddr*)&addr, &client_len); if (recv_num <= 0) { printf("Recv Data Error\n"); continue; } ++recv_count; res += recv_num; t_now = time(NULL); _now = time(NULL); _interval = _now - _old; // if (t_now - t_old >= 1) { // printf("recv_num= %d\n", recv_num); sprintf(buffer, "接受数据总大小:res = %lu kbytes, 数据包个数:%d 接受时间:%d s\n", res/1024, recv_count, _interval); if ((fputs(buffer,fp)) == 0) { printf("Fwrite Error\n"); return 1; } fflush(fp); printf("接收数据总大:res = %lu kbytes, 数据包个数:%d 接受时间:%d s\n", res / 1024, recv_count, _interval); t_old = t_now; } } free(fp); fp = NULL; return 0; }
求大神,写的程序有错误,新手找不出来,求指点
图书信息管理系统(学号尾数为4和9的同学完成) (1)设计要求 设计并实现一个图书信息管理系统。图书信息包括编号、书名、作者名、图书分类号、出版单位、出版时间、单价等。 (2)系统功能  系统以菜单的方式工作:要求界面清晰、美观、友好、易用。  图书信息导入功能:可以从文件导入图书信息。  浏览:能够显示所有图书信息,显示格式清晰、美观。  查询:能够根据图书分类号查询,并输出查询结果。  图书信息添加:可以添加新的图书信息,并实现信息存盘。  图书信息修改:输入图书编号,对相应的图书进行修改,并在修改后实现信息存盘。  图书信息删除:输入图书编号,对相应的图书进行删除,并在删除后实现信息存盘。 #include<iostream.h> /*引用库函数*/ #include <stdio.h> # include <string.h> # include <conio.h> # include <stdlib.h> # include <windows.h> typedef struct book_info//定义图书信息的结构体变量并声明新的类型名 { char AN[10]; /*登录号*/ char name[20]; /*书名*/ char author[20]; /*作者名*/ char clc[10]; /*分类名*/ char company[20]; /*出版单位*/ char date[20]; /*出版日期*/ char price[10]; /*价格*/ struct book_info *next; }Booklist,*Pointer; int num=0;//全局变量的定义 Pointer Head=NULL;//头指针为空 FILE *fp;//指向文件的指针 /*声明函数*/ int menu_select();/*主菜单函数*/ void Insert(Pointer * Head);/*录入函数*/ void Scan(Pointer Head);/*显示函数*/ void Search_name(Pointer Head);/*按书名查找函数*/ void Search_author(Pointer Head);/*按作者名查找函数*/ void Delete(Pointer * Head);//删除函数 void Update(Pointer Head);//修改函数 void Exit();//退出函数 void main()//主函数 { system("cls");/*运行前清屏*/ for(;;) { switch(menu_select()) { case 1:Insert(& Head); break; case 2:Scan(Head); break; case 3:Search_name(Head); break; case 4:Search_author(Head); break; case 5:Delete(&Head); break; case 6:Update(Head); break; case 0:Exit(); default: putchar('\a'); } } } menu_select()//主菜单函数 { int a; printf("\n\t\t\t欢迎使用图书信息管理系统\n\n\n\n\n\t\t ***** 请按任意键进入系统菜单! ***** \n"); getch(); system("cls"); printf("\t\t********************MENU*********************\n");//主菜单 printf("\t\t 1. 录入图书信息\n"); printf("\t\t 2. 浏览图书信息\n"); printf("\t\t 3. 按书名查询图书信息\n"); printf("\t\t 4. 按作者名查询图书信息\n"); printf("\t\t 5. 删除图书信息\n"); printf("\t\t 7. 修改图书信息\n"); printf("\t\t 0. 退出\n"); printf("\t\t***********************************************\n"); do { printf("\n\t请选择您所需要的功能:"); scanf("%d",&a); } while (a<0||a>6); return a; } void Insert(Pointer * Head) //录入图书信息函数 { char AN[10] ; char c; Pointer p,q,r; printf("\n\t\t**************** 请输入图书信息 ****************\n");/*交互输入*/ printf("\n\t\t请输入登录号:"); scanf("%s",AN); p=q= * Head;//检测登录号是否重复 while(p!=NULL) { if(strcmp(p->AN,AN)==0) { printf ("已经有相同的登录号:");return;} else {q=p;p=p->next;} } r=(Pointer)malloc(sizeof(Booklist)); r->next=NULL; if(r==NULL) {printf("分配空间失败!");return;} if(q==NULL) * Head=r; else {q->next=r;} strcpy(r->AN,AN); printf("\n\t\t输入书名:"); //录入图书信息 scanf("%s",r->name); getchar(); printf("\n\t\t输入作者名:"); scanf("%s",r->author); getchar(); printf("\n\t\t输入分类号:"); scanf("%s",r->clc) ; getchar(); printf("\n\t\t输入出版单位:"); scanf("%s",r->company) ; getchar(); printf("\n\t\t输入出版日期:"); gets(r->date) ; printf("\n\t\t输入价格:"); scanf("%s",r->price); do { printf("\n\t\t录入成功!!!!"); num++; printf("选择是否继续录入(Y/N)?:"); /*连续录入图书信息*/ getchar(); scanf("%c",&c); if(c=='y'||c=='Y') Insert(Head); else { if(c=='n'||c=='N') return; else printf("\n\t\t输入错误,请重新输入!!!"); } } while(c!='y'&&c!='n'&&c!='Y'&&c!='N'); } void Scan(Pointer Head) //显示图书信息函数 { Pointer p; p=Head; if(p==NULL) printf("记录为空");//检测是否有图书信息 else { printf("\n\t共有%d条记录",num); while(p!=NULL) { printf("\n\n\t\t登录号:%-10s",p->AN);//显示图书信息 printf("\n\t\t书名: %-20s",p->name); printf("\n\t\t作者名: %-20s",p->author); printf("\n\t\t分类号: %-10s",p->clc); printf("\n\t\t出版单位:%-20s",p->company); printf("\n\t\t出版时间:%-20s",p->date); printf("\n\t\t价格: ¥%-10s",p->price); p=p->next; } printf("\n\t\t请按任意键回到主菜单"); return; } } void Search_name(Pointer Head) //按书名查找函数 { int flag=0;//标记变量的初值 char name[10]; Pointer p; printf ("\n请输入需要查询的书名:"); scanf("%s",name); printf("\n\t\t************* 以下是您查找的信息 ***************"); p=Head; while(p!=NULL) { if(strcmp(p->name,name)==0)//查找符合的图书 { printf("\n\t登录号: %-10s",p->AN); printf("\n\t书名: %-20s",p->name); printf("\n\t作者名: %-20s",p->author); printf("\n\t分类号: %-10s",p->clc); printf("\n\t出版单位:%-20s",p->company); printf("\n\t出版时间:%-20s",p->date); printf("\n\t价格: ¥%-10s",p->price); flag=1;//找到标记变量设为1 p=p->next;//指针走到下一个节点 } else p=p->next; } if(flag==0) printf("\n\t\t没有相同书名纪录"); printf("\n\t\t请按任意键返回主菜单"); getchar(); } void Search_author(Pointer Head) //按作者名查找函数 { int flag=0; char author[10]; Pointer p; printf ("\n请输入需要查询的作者名:"); scanf("%s",author); printf("\n\t\t************* 以下是您查找的信息 ***************"); p=Head; while(p!=NULL)//查找符合的图书 { if(strcmp(p->author,author)==0)/*找到图书显示信息*/ { printf("\n\t登录号: %-10s",p->AN); printf("\n\t书名: %-20s",p->name); printf("\n\t作者名: %-20s",p->author); printf("\n\t分类号: %-10s",p->clc); printf("\n\t出版单位:%-20s",p->company); printf("\n\t出版时间:%-20s",p->date); printf("\n\t价格: ¥%-10s",p->price); flag=1; p=p->next; } else p=p->next; } if(flag==0) printf("\n\t\t没有相同作者名纪录"); printf("\n\t\t请按任意键返回主菜单"); getch(); } void Delete(Pointer *Head)/*删除函数*/ {int flag=1; char AN[10]; char c,z; Pointer p,q; printf("\n\t\t******************* 图书删除 *******************\n"); printf("\t请输入要删除图书的信息的登录号:"); scanf("%s",AN); p=q=*Head;/*查找符合条件的图书*/ while(p!=NULL&&flag) { if(strcmp(p->AN,AN)==0)/*找到该图书*/ { printf("\t\n登录号:%-10s",p->AN);//显示即将要删除的图书的信息 printf("\t\n书名:%-20s",p->name); printf("\t\n作者名:%-20s",p->author); printf("\t\n分类号:%-10s",p->clc); printf("\t\n出版单位:%-20s",p->company); printf("\t\n出版时间:%-20s",p->date); printf("\t\n价格:¥%-10s\n",p->price); printf("确定删除?确定请输Y,其它则不删除");//询问是否删除 getchar(); scanf("%c",&z); if(z=='Y'||z=='y') { if(p==*Head) {*Head=p->next;free(p);}/*删除图书信息*/ else {q->next=p->next;free(p);} flag=0; } else {printf("图书信息未删除,返回主菜单。"); return; } } else {q=p;p=p->next;}/*指针走到下一个节点*/ printf("\t\t删除成功!!!\n"); } if(flag) printf("\t没有找到可以删除的数据!!!"); do { printf("选择是否继续删除(Y/N)?:"); /*连续删除图书信息*/ getchar(); scanf("%c",&c); if(c=='y'||c=='Y') Delete(Head);/*继续删除*/ else { if(c=='n'||c=='N') return;/*不删除返回主菜单*/ else printf("\n\t\t输入错误,请重新输入!!!"); } } while(c!='y'&&c!='n'&&c!='Y'&&c!='N'); } void Update(Pointer Head)/*图书信息修改函数*/ { int flag=1; char AN[10]; char c; Pointer p; printf("\n\t\t***************** 图书信息修改 *****************\n"); printf("\t请输入要修改的图书的登录号:"); scanf("%s",AN);/*查找符合条件的图书*/ p=Head; while(p!=NULL&&flag) { if(strcmp(p->AN,AN)==0) { printf("\n\t\t请输入登录号:");/*修改图书信息*/ scanf("%s",p->AN); printf("\n\t\t输入书名:"); scanf("%s",p->name); getchar(); printf("\n\t\t输入作者名:"); scanf("%s",p->author); getchar(); printf("\n\t\t输入分类号:"); scanf("%s",p->clc) ; getchar(); printf("\n\t\t输入出版单位:"); scanf("%s",p->company) ; getchar(); printf("\n\t\t输入出版日期:"); gets(p->date); printf("\n\t\t输入价格:"); scanf("%s",p->price); flag=0; printf("修改成功!!\n"); } else p=p->next;/*指针走到下一个节点*/ } if(flag) printf("\n\t\t没有该图书记录!!!"); do { printf("选择是否继续修改(Y/N)?:"); /*连续修改图书信息*/ getchar(); scanf("%c",&c); if(c=='y'||c=='Y') Update(Head);/*继续修改*/ else {if(c=='n'||c=='N') return;//不修改,返回菜单 else printf("\n\t\t输入错误,请重新输入!!!"); } } while(c!='y'&&c!='n'&&c!='Y'&&c!='N');//输入错误则继续询问 } void Exit()/*退出程序的函数*/ {char c; do {printf("\n\t\t退出中......是否保存到文件(Y/N)?"); /*询问是否保存图书信息,防止丢失*/ getchar(); scanf("%c",&c); if(c=='y'||c=='Y') {Save(); exit(0); } else {if(c=='n'||c=='N') {exit(0); } else printf("\n\t\t输入错误,请重新输入!!!"); } } while(c!='y'&&c!='n'&&c!='Y'&&c!='N');//错误则继续询问 }
小白 提问 将小数全化成整数 如123.456变成123456
#include<stdio.h> int main() { double a; scanf("%lf",&a); while(a-int(a)>1e-6) a=a*10; printf("%lf",a); } 代码 但是有的数字如12.456时候可以 有的数字如123.456不行,应该是数据丢失了 但是怎么该?
滑动窗口协议模拟代码求补全!!!!!
//发送方sender.cpp文件 #include<iostream.h> #include<math.h> #include"sender.h" #include<stdio.h> #include<windows.h> #include<time.h> #include<winsock.h> #define SLEEPMS 1000 #define MAXPOOL 8 #define RECEIVE_MAX_LENGTH 8 #define MAX_LENGTH 8 #define SEND_MAX_LENGTH 8 CRITICAL_SECTION gCS; void InitLine(LinkQueue *q) //初始化队列 { q->front = q->rear = NULL; } int QueueEmpty(LinkQueue *q)//判断队列是否为空 { return q->front == NULL && q->rear == NULL; } frame QueueFront(LinkQueue *q) { if (QueueEmpty(q)) { printf("队列为空!\n"); Sleep(SLEEPMS); exit(0); } return q->front->head_data; } int QueueLen(LinkQueue *q)//计算队列长度 { if (QueueEmpty(q)) { return 0; } int num = 0; Framenode *p = q->front; while(p != NULL) { num++; p = p->next; } return num; } void GetFrameFromHost(LinkQueue *q) //数据帧发送完毕(收到确认帧)后,删除发送的数据帧(队头) { if(QueueLen(q) >= MAXPOOL) { printf("data %d 已准备好\n", q->front->head_data.head.seq); return; } Framenode *p=(Framenode *)malloc(sizeof(Framenode)); memset(p->head_data.head.data, 0, MAX_LENGTH); srand((unsigned)time(NULL)); p->head_data.size = rand() % MAX_LENGTH; // 帧大小随机生成 memset(p->head_data.head.data, '1', p->head_data.size); p->head_data.head.ack = -1; p->head_data.head.kind = data; p->head_data.head.seq = 0; p->next =NULL; if(QueueEmpty(q)) q->front = q->rear=p; // 首帧是待发送的帧 else { p->head_data.head.seq = (q->rear->head_data.head.seq + 1)%MAXPOOL; q->rear->next =p; q->rear =p; } printf("从主机得到:data %d,放入缓存\n", p->head_data.head.seq); GetFrameFromHost(q); // 由于实验需要,假设主机有足够多的数据帧要发送 } void DeLine(LinkQueue *q) //将帧数据保存供提交主机,curw是打开的待接收数据的窗口 { Framenode *p = NULL; if(QueueEmpty(q)) { printf("队列为空!\n"); } else { p = q->front; q->front = p->next; if (q->rear == p) q->rear = NULL; printf("发送data %d, %d 成功!从缓存中删除\n", p->head_data.head.seq, p->head_data.size); free(p); p = NULL; } } void main()//发送方主函数 { printf("建立连接 ... \n"); Begin: WORD wVersionRequested; WSADATA wsaData; //初始化socket库 wVersionRequested=MAKEWORD(1,1); //两个byte型合并成一个WORD型 int err=WSAStartup(wVersionRequested,&wsaData); if(err!=0) { Sleep(SLEEPMS); return; } if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) { WSACleanup(); //中止Windows Sockets服务 WSAStartup()成对使用 Sleep(SLEEPMS); return; } socketClient = socket(AF_INET,SOCK_STREAM,0);//监听的套接字 SOCKADDR_IN clientadd; clientadd.sin_addr.S_un.S_addr = inet_addr("127.0.0.1"); clientadd.sin_family = AF_INET; clientadd.sin_port = htons(7001);//设置连接端的IP、端口 if(SOCKET_ERROR==connect(socketClient,(SOCKADDR*)&clientadd,sizeof(SOCKADDR)) ) //连接 { WSACleanup(); Sleep(SLEEPMS); goto Begin; } char getData[RECEIVE_MAX_LENGTH]; memset(getData, 0, RECEIVE_MAX_LENGTH); //清零 if(recv(socketClient,getData,RECEIVE_MAX_LENGTH,0) == SOCKET_ERROR) //接受 { printf("接受连接提示信息出错!\n"); } else { printf("%s\n",getData); } char sendData[SEND_MAX_LENGTH]; memset(sendData, 0, SEND_MAX_LENGTH); strcpy(sendData, "你好接收方,我是发送方!"); if( SOCKET_ERROR == send(socketClient,sendData,strlen(sendData)+1,0) ) //发送 { printf("发送连接提示信息出错!\n"); WSACleanup(); closesocket(socketClient); Sleep(SLEEPMS); return; } printf("按任意键继续!\n"); while (!kbhit()) {}; //等待开始 Sleep(SLEEPMS); printf("1bit滑动窗口协议:发送方,发送窗口=1\n"); LinkQueue QueueQ; InitLine(&QueueQ); frame packetsend; //data frame packetreceive; // ack,nak unsigned long tick = GetTickCount(); int ret = 0; HANDLE hThread; while(1) { GetFrameFromHost(&QueueQ); //从主机取数据帧 memset(&packetsend, 0, sizeof(packetsend)); Sleep(SLEEPMS); printf("\n"); packetsend = QueueFront(&QueueQ); //取数据帧 ret = send(socketClient, (char *)&packetsend, sizeof(packetsend), 0);//发送data if(ret == SOCKET_ERROR) { printf("发送数据出错!\n"); continue; } printf("发送数据帧:data %d, %d\n", packetsend.head.seq, packetsend.size); const unsigned long timeOut = 5 * 1000; //设置超时计时器 5秒超时 memset(&packetreceive, 0, sizeof(packetreceive)); Sleep(SLEEPMS); printf("\n"); HANDLE hThrea; InitializeCriticalSection(&gCS); // 初始化临界区 hThread=CreateThread(NULL, 0, ReceiveFun, (LPVOID)&packetreceive, 0, NULL); int r = WaitForMultipleObjects(1, &hThread, TRUE, timeOut); DeleteCriticalSection(&gCS); //与InitializeCriticalSection(&gCS);成对使用 if(ret == SOCKET_ERROR || ret == SOCKET_DISCONN) { printf("接受出错!Press any key to continue\n"); while (!kbhit()) {}; continue; } if(r == WSA_WAIT_TIMEOUT) //判断超时 { TerminateThread(hThread, 0); //终止线程 printf("超时重传:data %d, %d\n", packetsend.head.seq,packetsend.size); } else if(packetsend.head.seq == packetreceive.head.ack) { srand((unsigned)time(NULL)); switch(rand() % 5) //假定产生随机结果,20%的概率超时 { case 0: printf("接收方发送回复超时(ack丢失模拟):%d\n", packetsend.head.seq); printf("超时重传:data %d, %d\n", packetsend.head.seq,packetsend.size); break; default: if(packetreceive.head.kind == ack) { printf("接受ack帧:ack %d\n", packetreceive.head.ack); DeLine(&QueueQ); } else if(packetreceive.head.kind == nak) { printf("接受nak帧:nak %d\n", packetsend.head.seq); } break; } } else printf("帧序号出错: %d\n", packetreceive.head.ack); if(GetTickCount() - tick > 20 * TIMEOUT) //设置时间20秒 { printf("持续时间20s. 按q退出,其他键继续\n"); int kbc = getchar(); if(kbc == 'q' || kbc == 'Q') break; } } printf("按任意键退出!\n"); while (!kbhit()) {}; Sleep(SLEEPMS); printf("谢谢使用!\n"); WSACleanup(); closesocket(socketClient); Sleep(SLEEPMS); } DWORD WINAPI ReceiveFun(LPVOID pArg) { EnterCriticalSection(&gCS);//进入critical section frame *packetreceive = (frame *)pArg; ret = recv(socketClient, (char *)packetreceive, sizeof(*packetreceive), 0); LeaveCriticalSection(&gCS); //线程用毕,离开critical section return ret; } //头文件sender.h部分 #include<iostream.h> typedef enum {data = 1,ack,nak,tout} frame_kind; //帧类型 typedef struct frame_head { frame_kind kind; //帧类型 unsigned int seq; //序列号 unsigned int ack; //确认号 unsigned char data[MAX_LENGTH]; //数据 }Head; typedef struct frame { frame_head head; //帧头 unsigned int size; //数据的大小 } Frame; typedef struct framenode //队列节点类型 { frame head_data; struct framenode *next; } Framenode; typedef struct { Framenode *front; //队头指针 Framenode *rear; //队尾指针 } LinkQueue;
STM32为什么用串口接收数据不全,时常丢失?
``` ```#include "stm32f10x.h" #include "usart.h" #include "delay.h" void My_USART1_Init(void) { GPIO_InitTypeDef GPIO_InitStrue; USART_InitTypeDef USART_InitStrue; NVIC_InitTypeDef NVIC_InitStrue; //①使能GPIOA和串口1 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); //②初始化GPIOA两个引脚 GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9; GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz; GPIO_Init(GPIOA,&GPIO_InitStrue); GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10; GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz; GPIO_Init(GPIOA,&GPIO_InitStrue); //③串口初始化 //波特率 USART_InitStrue.USART_BaudRate=115200; //硬件控制 USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_InitStrue.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //奇偶验证 USART_InitStrue.USART_Parity=USART_Parity_No; //停止位 USART_InitStrue.USART_StopBits=USART_StopBits_1; //字长 USART_InitStrue.USART_WordLength=USART_WordLength_8b; USART_Init(USART1,&USART_InitStrue); //串口使能 USART_Cmd(USART1,ENABLE);//③ USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//开启接受中断 USART_ITConfig(USART1,USART_IT_ORE,ENABLE);//开启溢出中断 //初始化中断 NVIC_InitStrue.NVIC_IRQChannel=USART1_IRQn; NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStrue.NVIC_IRQChannelSubPriority=1; NVIC_Init(&NVIC_InitStrue); } u8 usart_buf[4][USART_REC_LEN];//接收缓冲,最大USART_REC_LEN个字节 static volatile u16 count=0;//接收状态标记 static volatile int p=0; void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)//开启接收中断 { USART_ClearITPendingBit(USART1,USART_IT_RXNE);//清除标志中断位 p = (count / USART_REC_LEN) % 4; usart_buf[p][count % USART_REC_LEN] = USART_ReceiveData(USART1); count++; } } int main(void) { //要使用中断,先要中断分组,一般在主函数的开头 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); My_USART1_Init(); delay_init(); while(1){ if(count > 0){ if(count % 256 == 0){ for(int i = 0; i < 256; i++){ USART_SendData(USART1,usart_buf[p][i]); while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET); } printf("\r\n\r\n"); delay_ms(100); } } }; } ![图片说明](https://img-ask.csdn.net/upload/201910/31/1572495626_268037.png)
TCP IP协议客户端在全志R16 开发板上的时候丢失数据
1.服务器采用多线程客户端数据处理 void build_server() { int server_fd = 0,client_fd = 0; struct sockaddr_in address; memset(&address,0,sizeof(address)); server_fd = socket(AF_INET,1,0); address.sin_family = AF_INET; address.sin_port = htons(8998); address.sin_addr.s_addr = INADDR_ANY; if(bind(server_fd,(struct sockaddr*)&address,sizeof(address))<0) { perror("service bind error"); exit(1); } if(listen(server_fd,1024) < 0) { perror("service listen error"); exit(1); } #if 1 while(1) { printf("正在链接.......\n"); client_fd = accept(server_fd,NULL,NULL); usleep(10000); if(client_fd < 0) { printf("退出\n"); return; }else{ #endif pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); pthread_create(&thread,&attr,speech_request,(void*)client_fd); } } return ; } 线程处理如下: struct post_content { int contType; int contLength; char buff[2048]; }; struct post_content recvData = {0}; while(1) { memset(&recvData,0,sizeof(struct post_content)); retVal = recv(clientFd,&recvData,sizeof(struct post_content),0); ................................ 客户端请求发送 struct post_content 大小的数据 2056字节 ,, 问题: 当客户端请求跑在PC unbuntu 下面时候,服务器接收数据是正常的, 当客户端跑在全志R16 的开发板上的时候,板子上发送 struct post_content 大小的数据 ,服务器 一次只能接收到 1000多或者几百多字节数据,现在的做法是手动将数据拷贝到 struct post_content 大小。不太理解为什么TCP IP 会丢失数据
别人给的各种运动目标检测方法的代码,不知道少了什么东西一直调不通
1.我用的是VS2013,配置的是OpenCV3.4.0,运行如下程序的时候就说有许多未定义的标识符,琢磨了好久就是不知道哪里出了问题。求大神帮我看看程序。看看哪里出了问题,,需要的话我可以把整个程序发过去,(有偿) ``` #include <opencv2/highgui/highgui.hpp> #include <opencv2/core/core.hpp> #include <stdio.h> #include <stdlib.h> //#include "cvaux.h" #include "codeb.h" int CVCONTOUR_APPROX_LEVEL = 2; int CVCLOSE_ITR = 1; #define CV_CVX_WHITE CV_RGB(0xff,0xff,0xff) #define CV_CVX_BLACK CV_RGB(0x00,0x00,0x00) codeBook* cA; codeBook* cC; codeBook* cD; int maxMod[CHANNELS]; int minMod[CHANNELS]; unsigned cbBounds[CHANNELS]; bool ch[CHANNELS]; int nChannels = CHANNELS; int imageLen = 0; uchar *pColor; int Td; int Tadd; int Tdel; int T=50; int Fadd=35; int Tavgstale=50; int Fd=2; int Tavgstale_cD=50; int fgcount=0; float beta=0.1f; float gamma=0.1f; float forgratio=0.0f; float Tadap_update=0.4f; int clear_stale_entries(codeBook &c); uchar background_Diff(uchar *p, codeBook &c, int numChannels, int *minMod, int *maxMod); int update_codebook_model(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels); int trainig_codebook(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels); int training_clear_stale_entries(codeBook &c); int det_update_codebook_cC(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels); int det_update_codebook_cD(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels, int numframe); int realtime_clear_stale_entries_cC(codeBook &c, int FrmNum); int realtime_clear_stale_entries_cD(codeBook &c, int FrmNum); int cD_to_cC(codeBook &d, codeBook &c, int FrmNum); uchar background_diff_realtime(uchar* p,codeBook& c,int numChannels,int* minMod,int* maxMod); void help() { printf( "***Keep the focus on the video windows, NOT the consol***\n" "INTERACTIVE PARAMETERS:\n" "\tESC,q,Q - quit the program\n" "\th - print this help\n" "\tp - pause toggle\n" "\ts - single step\n" "\tr - run mode (single step off)\n" "=== CODEBOOK PARAMS ===\n" "\ty,u,v- only adjust channel 0(y) or 1(u) or 2(v) respectively\n" "\ta - adjust all 3 channels at once\n" "\tb - adjust both 2 and 3 at once\n" "\ti,o - bump upper threshold up,down by 1\n" "\tk,l - bump lower threshold up,down by 1\n" "\tz,x - bump Fadd threshold up,down by 1\n" "\tn,m - bump Tavgstale threshold up,down by 1\n" "\t Fadd小更新快,Tavgstale大更新快\n" ); } int count_Segmentation(codeBook *c, IplImage *I, int numChannels, int *minMod, int *maxMod) { int count = 0,i; uchar *pColor; int imageLen = I->width * I->height; //GET BASELINE NUMBER OF FG PIXELS FOR Iraw pColor = (uchar *)((I)->imageData); for(i=0; i<imageLen; i++) { if(background_Diff(pColor, c[i], numChannels, minMod, maxMod)) count++; pColor += 3; } fgcount=count; return(fgcount); } void connected_Components(IplImage *mask, int poly1_hull0, float perimScale, int *num, CvRect *bbs, CvPoint *centers) { static CvMemStorage* mem_storage = NULL; static CvSeq* contours = NULL; //CLEAN UP RAW MASK cvMorphologyEx( mask, mask, NULL, NULL, CV_MOP_OPEN, CVCLOSE_ITR ); cvMorphologyEx( mask, mask, NULL, NULL, CV_MOP_CLOSE, CVCLOSE_ITR ); //FIND CONTOURS AROUND ONLY BIGGER REGIONS if( mem_storage==NULL ) mem_storage = cvCreateMemStorage(0); else cvClearMemStorage(mem_storage); CvContourScanner scanner = cvStartFindContours(mask,mem_storage,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE); CvSeq* c; int numCont = 0; while( (c = cvFindNextContour( scanner )) != NULL ) { double len = cvContourPerimeter( c ); double q = (mask->height + mask->width) /perimScale; //calculate perimeter len threshold if( len < q ) //Get rid of blob if it's perimeter is too small { cvSubstituteContour( scanner, NULL ); } else //Smooth it's edges if it's large enough { CvSeq* c_new; if(poly1_hull0) //Polygonal approximation of the segmentation c_new = cvApproxPoly(c,sizeof(CvContour),mem_storage,CV_POLY_APPROX_DP, CVCONTOUR_APPROX_LEVEL,0); else //Convex Hull of the segmentation c_new = cvConvexHull2(c,mem_storage,CV_CLOCKWISE,1); cvSubstituteContour( scanner, c_new ); numCont++; } } contours = cvEndFindContours( &scanner ); // PAINT THE FOUND REGIONS BACK INTO THE IMAGE cvZero( mask ); IplImage *maskTemp; //CALC CENTER OF MASS AND OR BOUNDING RECTANGLES if(num != NULL) { int N = *num, numFilled = 0, i=0; CvMoments moments; double M00, M01, M10; maskTemp = cvCloneImage(mask); for(i=0, c=contours; c != NULL; c = c->h_next,i++ ) { if(i < N) //Only process up to *num of them { cvDrawContours(maskTemp,c,CV_CVX_WHITE, CV_CVX_WHITE,-1,CV_FILLED,8); //Find the center of each contour if(centers != NULL) { cvMoments(maskTemp,&moments,1); M00 = cvGetSpatialMoment(&moments,0,0); M10 = cvGetSpatialMoment(&moments,1,0); M01 = cvGetSpatialMoment(&moments,0,1); centers[i].x = (int)(M10/M00); centers[i].y = (int)(M01/M00); } //Bounding rectangles around blobs if(bbs != NULL) { bbs[i] = cvBoundingRect(c); } cvZero(maskTemp); numFilled++; } //Draw filled contours into mask cvDrawContours(mask,c,CV_CVX_WHITE,CV_CVX_WHITE,-1,CV_FILLED,8); //draw to central mask } //end looping over contours *num = numFilled; cvReleaseImage( &maskTemp); } else { for( c=contours; c != NULL; c = c->h_next ) { cvDrawContours(mask,c,CV_CVX_WHITE, CV_CVX_BLACK,-1,CV_FILLED,8); } } } //////////////////////////// int main(int argc, char** argv) { IplImage* temp1 = NULL; IplImage* temp2 = NULL; IplImage* result = NULL; IplImage* result1 = NULL; IplImage* result2 = NULL; CvBGStatModel* bg_model = 0; CvBGStatModel* bg_model1=0; IplImage* rawImage = 0; IplImage* yuvImage = 0; IplImage* rawImage1 = 0; IplImage* pFrImg = 0; IplImage* pFrImg1= 0; IplImage* pFrImg2= 0; IplImage* ImaskCodeBookCC = 0; CvCapture* capture = 0; int c,n; maxMod[0] = 25; minMod[0] = 35; maxMod[1] = 8; minMod[1] = 8; maxMod[2] = 8; minMod[2] = 8; argc=2; argv[1]="intelligentroom_raw.avi"; if( argc > 2 ) { fprintf(stderr, "Usage: bkgrd [video_file_name]\n"); return -1; } if (argc ==1) if( !(capture = cvCaptureFromCAM(-1))) { fprintf(stderr, "Can not open camera.\n"); return -2; } if(argc == 2) if( !(capture = cvCaptureFromFile(argv[1]))) { fprintf(stderr, "Can not open video file %s\n", argv[1]); return -2; } bool pause = false; bool singlestep = false; if( capture ) { cvNamedWindow( "原视频序列图像", 1 ); cvNamedWindow("不实时更新的Codebook算法[本文]",1); cvNamedWindow("实时更新的Codebook算法[本文]",1); cvNamedWindow("基于MOG的方法[Chris Stauffer'2001]",1); cvNamedWindow("三帧差分", 1); cvNamedWindow("基于Bayes decision的方法[Liyuan Li'2003]", 1); cvMoveWindow("原视频序列图像", 0, 0); cvMoveWindow("不实时更新的Codebook算法[本文]", 360, 0); cvMoveWindow("实时更新的Codebook算法[本文]", 720, 350); cvMoveWindow("基于MOG的方法[Chris Stauffer'2001]", 0, 350); cvMoveWindow("三帧差分", 720, 0); cvMoveWindow("基于Bayes decision的方法[Liyuan Li'2003]",360, 350); int nFrmNum = -1; for(;;) { if(!pause) { rawImage = cvQueryFrame( capture ); ++nFrmNum; printf("第%d帧\n",nFrmNum); if(!rawImage) break; } if(singlestep) { pause = true; } if(0 == nFrmNum) { printf(". . . wait for it . . .\n"); temp1 = cvCreateImage(cvGetSize(rawImage), IPL_DEPTH_8U, 3); temp2 = cvCreateImage(cvGetSize(rawImage), IPL_DEPTH_8U, 3); result1 = cvCreateImage(cvGetSize(rawImage), IPL_DEPTH_8U, 1); result2 = cvCreateImage(cvGetSize(rawImage), IPL_DEPTH_8U, 1); result = cvCreateImage(cvGetSize(rawImage), IPL_DEPTH_8U, 1); bg_model = cvCreateGaussianBGModel(rawImage); bg_model1 = cvCreateFGDStatModel(rawImage); rawImage1 = cvCreateImage( cvGetSize(rawImage), IPL_DEPTH_8U, 3 ); yuvImage = cvCloneImage(rawImage); pFrImg = cvCreateImage( cvGetSize(rawImage), IPL_DEPTH_8U, 1 ); pFrImg1 = cvCreateImage( cvGetSize(rawImage), IPL_DEPTH_8U, 1 ); pFrImg2 = cvCreateImage( cvGetSize(rawImage), IPL_DEPTH_8U, 1 ); ImaskCodeBookCC = cvCreateImage( cvGetSize(rawImage), IPL_DEPTH_8U, 1 ); imageLen = rawImage->width*rawImage->height; cA = new codeBook [imageLen]; cC = new codeBook [imageLen]; cD = new codeBook [imageLen]; for(int f = 0; f<imageLen; f++) { cA[f].numEntries = 0; cA[f].t = 0; cC[f].numEntries = 0; cC[f].t = 0; cD[f].numEntries = 0; cD[f].t = 0; } for(int nc=0; nc<nChannels;nc++) { cbBounds[nc] = 10; } ch[0] = true; ch[1] = true; ch[2] = true; } if( rawImage ) { if(!pause) { cvSmooth(rawImage, rawImage1, CV_GAUSSIAN,3,3); cvChangeDetection(temp1, temp2, result1); cvChangeDetection(rawImage1, temp1, result2); cvAnd(result1, result2, result, NULL); cvCopy(temp1,temp2, NULL); cvCopy(rawImage,temp1, NULL); cvUpdateBGStatModel( rawImage, bg_model ); cvUpdateBGStatModel( rawImage, bg_model1 ); } cvCvtColor( rawImage1, yuvImage, CV_BGR2YCrCb ); if( !pause && nFrmNum >= 1 && nFrmNum < T ) { pColor = (uchar *)((yuvImage)->imageData); for(int c=0; c<imageLen; c++) { update_codebook_model(pColor, cA[c],cbBounds,nChannels); trainig_codebook(pColor, cC[c],cbBounds,nChannels); pColor += 3; } } if( nFrmNum == T) { for(c=0; c<imageLen; c++) { clear_stale_entries(cA[c]); training_clear_stale_entries(cC[c]); } } if(nFrmNum > T) { pColor = (uchar *)((yuvImage)->imageData); uchar maskPixelCodeBook; uchar maskPixelCodeBook1; uchar maskPixelCodeBook2; uchar *pMask = (uchar *)((pFrImg)->imageData); uchar *pMask1 = (uchar *)((pFrImg1)->imageData); uchar *pMask2 = (uchar *)((pFrImg2)->imageData); for(int c=0; c<imageLen; c++) { //本文中不带自动背景更新的算法输出 maskPixelCodeBook1=background_Diff(pColor, cA[c],nChannels,minMod,maxMod); *pMask1++ = maskPixelCodeBook1; //本文中带自动背景更新的算法输出 if ( !pause && det_update_codebook_cC(pColor, cC[c],cbBounds,nChannels)) { det_update_codebook_cD(pColor, cD[c],cbBounds,nChannels, nFrmNum); realtime_clear_stale_entries_cD(cD[c], nFrmNum); cD_to_cC(cD[c], cC[c], (nFrmNum - T)/5); } else { realtime_clear_stale_entries_cC(cC[c], nFrmNum); } maskPixelCodeBook2=background_Diff(pColor, cC[c],nChannels,minMod,maxMod); *pMask2++ = maskPixelCodeBook2; pColor += 3; } cvCopy(pFrImg2,ImaskCodeBookCC); if(!pause) { count_Segmentation(cC,yuvImage,nChannels,minMod,maxMod); forgratio = (float) (fgcount)/ imageLen; } } bg_model1->foreground->origin=1; bg_model->foreground->origin=1; pFrImg->origin=1; pFrImg1->origin=1; pFrImg2->origin=1; ImaskCodeBookCC->origin=1; result->origin=1; //connected_Components(pFrImg1,1,40); //connected_Components(pFrImg2,1,40); cvShowImage("基于MOG的方法[Chris Stauffer'2001]", bg_model->foreground); cvShowImage( "原视频序列图像", rawImage ); cvShowImage("三帧差分", result); cvShowImage( "不实时更新的Codebook算法[本文]",pFrImg1); cvShowImage("实时更新的Codebook算法[本文]",pFrImg2); cvShowImage("基于Bayes decision的方法[Liyuan Li'2003]", bg_model1->foreground); c = cvWaitKey(1)&0xFF; //End processing on ESC, q or Q if(c == 27 || c == 'q' || c == 'Q') break; //Else check for user input switch(c) { case 'h': help(); break; case 'p': pause ^= 1; break; case 's': singlestep = 1; pause = false; break; case 'r': pause = false; singlestep = false; break; //CODEBOOK PARAMS case 'y': case '0': ch[0] = 1; ch[1] = 0; ch[2] = 0; printf("CodeBook YUV Channels active: "); for(n=0; n<nChannels; n++) printf("%d, ",ch[n]); printf("\n"); break; case 'u': case '1': ch[0] = 0; ch[1] = 1; ch[2] = 0; printf("CodeBook YUV Channels active: "); for(n=0; n<nChannels; n++) printf("%d, ",ch[n]); printf("\n"); break; case 'v': case '2': ch[0] = 0; ch[1] = 0; ch[2] = 1; printf("CodeBook YUV Channels active: "); for(n=0; n<nChannels; n++) printf("%d, ",ch[n]); printf("\n"); break; case 'a': //All case '3': ch[0] = 1; ch[1] = 1; ch[2] = 1; printf("CodeBook YUV Channels active: "); for(n=0; n<nChannels; n++) printf("%d, ",ch[n]); printf("\n"); break; case 'b': //both u and v together ch[0] = 0; ch[1] = 1; ch[2] = 1; printf("CodeBook YUV Channels active: "); for(n=0; n<nChannels; n++) printf("%d, ",ch[n]); printf("\n"); break; case 'z': printf(" Fadd加1 "); Fadd += 1; printf("Fadd=%.4d\n",Fadd); break; case 'x': printf(" Fadd减1 "); Fadd -= 1; printf("Fadd=%.4d\n",Fadd); break; case 'n': printf(" Tavgstale加1 "); Tavgstale += 1; printf("Tavgstale=%.4d\n",Tavgstale); break; case 'm': printf(" Tavgstale减1 "); Tavgstale -= 1; printf("Tavgstale=%.4d\n",Tavgstale); break; case 'i': //modify max classification bounds (max bound goes higher) for(n=0; n<nChannels; n++) { if(ch[n]) maxMod[n] += 1; printf("%.4d,",maxMod[n]); } printf(" CodeBook High Side\n"); break; case 'o': //modify max classification bounds (max bound goes lower) for(n=0; n<nChannels; n++) { if(ch[n]) maxMod[n] -= 1; printf("%.4d,",maxMod[n]); } printf(" CodeBook High Side\n"); break; case 'k': //modify min classification bounds (min bound goes lower) for(n=0; n<nChannels; n++) { if(ch[n]) minMod[n] += 1; printf("%.4d,",minMod[n]); } printf(" CodeBook Low Side\n"); break; case 'l': //modify min classification bounds (min bound goes higher) for(n=0; n<nChannels; n++) { if(ch[n]) minMod[n] -= 1; printf("%.4d,",minMod[n]); } printf(" CodeBook Low Side\n"); break; } } } cvReleaseCapture( &capture ); cvReleaseBGStatModel((CvBGStatModel**)&bg_model); cvReleaseBGStatModel((CvBGStatModel**)&bg_model1); cvDestroyWindow( "原视频序列图像" ); cvDestroyWindow( "不实时更新的Codebook算法[本文]"); cvDestroyWindow( "实时更新的Codebook算法[本文]"); cvDestroyWindow( "基于MOG的方法[Chris Stauffer'2001]"); cvDestroyWindow( "三帧差分" ); cvDestroyWindow( "基于Bayes decision的方法[Liyuan Li'2003]"); cvReleaseImage(&temp1); cvReleaseImage(&temp2); cvReleaseImage(&result); cvReleaseImage(&result1); cvReleaseImage(&result2); cvReleaseImage(&pFrImg); cvReleaseImage(&pFrImg1); cvReleaseImage(&pFrImg2); if(yuvImage) cvReleaseImage(&yuvImage); if(rawImage) cvReleaseImage(&rawImage); if(rawImage1) cvReleaseImage(&rawImage1); if(ImaskCodeBookCC) cvReleaseImage(&ImaskCodeBookCC); delete [] cA; delete [] cC; delete [] cD; } else { printf("\n\nDarn, Something wrong with the parameters\n\n"); help(); } return 0; } int clear_stale_entries(codeBook &c) { int staleThresh = c.t>>1; int *keep = new int [c.numEntries]; int keepCnt = 0; for(int i=0; i<c.numEntries; i++) { if(c.cb[i]->stale > staleThresh) keep[i] = 0; else { keep[i] = 1; keepCnt += 1; } } c.t = 0; code_element **foo = new code_element* [keepCnt]; int k=0; for(int ii=0; ii<c.numEntries; ii++) { if(keep[ii]) { foo[k] = c.cb[ii]; foo[k]->t_last_update = 0; k++; } } delete [] keep; delete [] c.cb; c.cb = foo; int numCleared = c.numEntries - keepCnt; c.numEntries = keepCnt; return(numCleared); } uchar background_Diff(uchar *p, codeBook &c, int numChannels, int *minMod, int *maxMod) { int matchChannel; int i; for(i=0; i<c.numEntries; i++) { matchChannel = 0; for(int n=0; n<numChannels; n++) { if((c.cb[i]->min[n] - minMod[n] <= *(p+n)) && (*(p+n) <= c.cb[i]->max[n] + maxMod[n])) { matchChannel++; } else { break; } } if(matchChannel == numChannels) { break; } } if(i >= c.numEntries) return(255); return(0); } int update_codebook_model(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels) { if(c.numEntries == 0) c.t = 0; c.t += 1; unsigned int high[3],low[3]; int matchChannel; float avg[3]; for(int i=0; i<c.numEntries; i++) { matchChannel = 0; for(int n=0; n<numChannels; n++) { if((c.cb[i]->learnLow[n] <= *(p+n)) && (*(p+n) <= c.cb[i]->learnHigh[n])) { matchChannel++; } } if(matchChannel == numChannels) { for(int n=0; n<numChannels; n++) { avg[n] = (c.cb[i]->f * c.cb[i]->avg[n] + *(p+n))/(c.cb[i]->f + 1); c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } c.cb[i]->f += 1; c.cb[i]->t_last_update = c.t; int negRun = c.t - c.cb[i]->t_last_update; if(c.cb[i]->stale < negRun) c.cb[i]->stale = negRun; break; } } for(int n=0; n<numChannels; n++) { high[n] = *(p+n)+*(cbBounds+n); if(high[n] > 255) high[n] = 255; low[n] = *(p+n)-*(cbBounds+n); if(low[n] < 0) low[n] = 0; } if(i == c.numEntries) { code_element **foo = new code_element* [c.numEntries+1]; for(int ii=0; ii<c.numEntries; ii++) { foo[ii] = c.cb[ii]; } foo[c.numEntries] = new code_element; if(c.numEntries) delete [] c.cb; c.cb = foo; for(int n=0; n<numChannels; n++) { c.cb[c.numEntries]->avg[n] = *(p+n); c.cb[c.numEntries]->max[n] = *(p+n); c.cb[c.numEntries]->min[n] = *(p+n); c.cb[c.numEntries]->learnHigh[n] = high[n]; c.cb[c.numEntries]->learnLow[n] = low[n]; } c.cb[c.numEntries]->f = 1; c.cb[c.numEntries]->stale = c.t-1; c.cb[c.numEntries]->t_first_update = c.t; c.cb[c.numEntries]->t_last_update = c.t; c.numEntries += 1; } for(int s=0; s<c.numEntries; s++) { int negRun = c.t - c.cb[s]->t_last_update + c.cb[s]->t_first_update -1 ; if(c.cb[s]->stale < negRun) c.cb[s]->stale = negRun; } for(n=0; n<numChannels; n++) { if(c.cb[i]->learnHigh[n] < high[n]) c.cb[i]->learnHigh[n] += 1; if(c.cb[i]->learnLow[n] > low[n]) c.cb[i]->learnLow[n] -= 1; } return(i); } int trainig_codebook(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels) { if(c.numEntries == 0) c.t = 0; c.t += 1; unsigned int high[3],low[3]; int matchChannel; float avg[3]; for(int i=0; i<c.numEntries; i++) { matchChannel = 0; for(int n=0; n<numChannels; n++) { if((c.cb[i]->learnLow[n] <= *(p+n)) && (*(p+n) <= c.cb[i]->learnHigh[n])) { matchChannel++; } } if(matchChannel == numChannels) { for(int n=0; n<numChannels; n++) { avg[n] = (c.cb[i]->f * c.cb[i]->avg[n] + *(p+n))/(c.cb[i]->f + 1); c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } c.cb[i]->f += 1; c.cb[i]->t_last_update = c.t; int negRun = c.t - c.cb[i]->t_last_update; if(c.cb[i]->stale < negRun) c.cb[i]->stale = negRun; if (i!=0) { code_element **fo = new code_element* [c.numEntries]; fo[0] = c.cb[i]; for(int h=0; h<i; h++) { fo[h+1] = c.cb[h]; } for(int h=i+1; h<c.numEntries; h++) { fo[h] = c.cb[h]; } if(c.numEntries) delete [] c.cb; c.cb = fo; } break; } } for(int n=0; n<numChannels; n++) { high[n] = *(p+n)+*(cbBounds+n); if(high[n] > 255) high[n] = 255; low[n] = *(p+n)-*(cbBounds+n); if(low[n] < 0) low[n] = 0; } if(i == c.numEntries) { code_element **foo = new code_element* [c.numEntries+1]; for(int ii=0; ii<c.numEntries; ii++) { foo[ii] = c.cb[ii]; } foo[c.numEntries] = new code_element; if(c.numEntries) delete [] c.cb; c.cb = foo; for(n=0; n<numChannels; n++) { c.cb[c.numEntries]->avg[n] = *(p+n); c.cb[c.numEntries]->max[n] = *(p+n); c.cb[c.numEntries]->min[n] = *(p+n); c.cb[c.numEntries]->learnHigh[n] = high[n]; c.cb[c.numEntries]->learnLow[n] = low[n]; } c.cb[c.numEntries]->f = 1; c.cb[c.numEntries]->stale = c.t-1; c.cb[c.numEntries]->t_first_update = c.t; c.cb[c.numEntries]->t_last_update = c.t; c.numEntries += 1; } for(int s=0; s<c.numEntries; s++) { int negRun = c.t - c.cb[s]->t_last_update + c.cb[s]->t_first_update -1 ; if(c.cb[s]->stale < negRun) c.cb[s]->stale = negRun; } for(int n=0; n<numChannels; n++) { if(c.cb[i]->learnHigh[n] < high[n]) c.cb[i]->learnHigh[n] += 1; if(c.cb[i]->learnLow[n] > low[n]) c.cb[i]->learnLow[n] -= 1; } return(i); } int training_clear_stale_entries(codeBook &c) { int staleThresh = c.t>>1; int *keep = new int [c.numEntries]; int keepCnt = 0; for(int i=0; i<c.numEntries; i++) { if(c.cb[i]->stale > staleThresh) keep[i] = 0; else { keep[i] = 1; keepCnt += 1; } } code_element **foo = new code_element* [keepCnt]; int k=0; for(int ii=0; ii<c.numEntries; ii++) { if(keep[ii]) { foo[k] = c.cb[ii]; k++; } } delete [] keep; delete [] c.cb; c.cb = foo; int numCleared = c.numEntries - keepCnt; c.numEntries = keepCnt; return(numCleared); } int det_update_codebook_cC(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels) { c.t += 1; int matchChannel; float avg[3]; int learnLow[3],learnHigh[3]; for(int i=0; i<c.numEntries; i++) { matchChannel = 0; for(int n=0; n<numChannels; n++) { if (forgratio >= Tadap_update ) { learnLow[n] = c.cb[i]->learnLow[n] * (1 - gamma); c.cb[i]->learnLow[n] = learnLow[n]; learnHigh[n] = c.cb[i]->learnHigh[n] * (1 + gamma); c.cb[i]->learnHigh[n] = learnHigh[n]; } if((c.cb[i]->learnLow[n] <= *(p+n)) && (*(p+n) <= c.cb[i]->learnHigh[n])) { matchChannel++; } } if(matchChannel == numChannels) { if (forgratio >= Tadap_update ) { for(int n=0; n<numChannels; n++) { avg[n] = (1 - beta) * c.cb[i]->avg[n] + *(p+n) * beta; c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } } else { for(int n=0; n<numChannels; n++) { avg[n] = (c.cb[i]->f * c.cb[i]->avg[n] + *(p+n))/(c.cb[i]->f + 1); c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } } int negRun = c.t - c.cb[i]->t_last_update; if(c.cb[i]->stale < negRun) c.cb[i]->stale = negRun; c.cb[i]->t_last_update = c.t; c.cb[i]->f += 1; break; } } if( i == c.numEntries) return (i); return(0); } int det_update_codebook_cD(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels, int numframe) { if(c.numEntries == 0) c.t = numframe -1; c.t += 1; unsigned int high[3],low[3]; int matchChannel; float avg[3]; int learnLow[3],learnHigh[3]; for(int i=0; i<c.numEntries; i++) { matchChannel = 0; for(int n=0; n<numChannels; n++) { if (forgratio >= Tadap_update ) { learnLow[n] = c.cb[i]->learnLow[n] * (1 - gamma); c.cb[i]->learnLow[n] = learnLow[n]; learnHigh[n] = c.cb[i]->learnHigh[n] * (1 + gamma); c.cb[i]->learnHigh[n] = learnHigh[n]; } if((c.cb[i]->learnLow[n] <= *(p+n)) && (*(p+n) <= c.cb[i]->learnHigh[n])) { matchChannel++; } } if(matchChannel == numChannels) { if (forgratio >= Tadap_update ) { for(int n=0; n<numChannels; n++) { avg[n] = (1 - beta) * c.cb[i]->avg[n] + *(p+n) * beta; c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } } else { for(int n=0; n<numChannels; n++) { avg[n] = (c.cb[i]->f * c.cb[i]->avg[n] + *(p+n))/(c.cb[i]->f + 1); c.cb[i]->avg[n] = avg[n]; if(c.cb[i]->max[n] < *(p+n)) { c.cb[i]->max[n] = *(p+n); } else if(c.cb[i]->min[n] > *(p+n)) { c.cb[i]->min[n] = *(p+n); } } } int negRun = c.t - c.cb[i]->t_last_update; if(c.cb[i]->stale < negRun) c.cb[i]->stale = negRun; c.cb[i]->f += 1; c.cb[i]->t_last_update = c.t; break; } } for(int n=0; n<numChannels; n++) { high[n] = *(p+n)+*(cbBounds+n); if(high[n] > 255) high[n] = 255; low[n] = *(p+n)-*(cbBounds+n); if(low[n] < 0) low[n] = 0; } if(i == c.numEntries) { code_element **foo = new code_element* [c.numEntries+1]; for(int ii=0; ii<c.numEntries; ii++) { foo[ii] = c.cb[ii]; } foo[c.numEntries] = new code_element; if(c.numEntries) delete [] c.cb; c.cb = foo; for(int n=0; n<numChannels; n++) { c.cb[c.numEntries]->avg[n] = *(p+n); c.cb[c.numEntries]->max[n] = *(p+n); c.cb[c.numEntries]->min[n] = *(p+n); c.cb[c.numEntries]->learnHigh[n] = high[n]; c.cb[c.numEntries]->learnLow[n] = low[n]; } c.cb[c.numEntries]->f = 1; c.cb[c.numEntries]->stale = 0; c.cb[c.numEntries]->t_first_update = c.t; c.cb[c.numEntries]->t_last_update = c.t; c.numEntries += 1; } for(int s=0; s<c.numEntries; s++) { int negRun = c.t - c.cb[s]->t_last_update; if(c.cb[s]->stale < negRun) c.cb[s]->stale = negRun; } for(int n=0; n<numChannels; n++) { if(c.cb[i]->learnHigh[n] < high[n]) c.cb[i]->learnHigh[n] += 1; if(c.cb[i]->learnLow[n] > low[n]) c.cb[i]->learnLow[n] -= 1; } return(i); } int realtime_clear_stale_entries_cC(codeBook &c, int FrmNum) { int staleThresh = FrmNum/2; int *keep = new int [c.numEntries]; int keepCnt = 0; for(int i=0; i<c.numEntries; i++) { if(c.cb[i]->stale > staleThresh) keep[i] = 0; else { keep[i] = 1; keepCnt += 1; } } c.t = 0; code_element **foo = new code_element* [keepCnt]; int k=0; for(int ii=0; ii<c.numEntries; ii++) { if(keep[ii]) { foo[k] = c.cb[ii]; k++; } } delete [] keep; delete [] c.cb; c.cb = foo; int numCleared = c.numEntries - keepCnt; c.numEntries = keepCnt; return(numCleared); } int realtime_clear_stale_entries_cD(codeBook &c, int FrmNum) { int *keep = new int [c.numEntries]; int keepCnt = 0; for(int i=0; i<c.numEntries; i++) { if(c.cb[i]->f <=Fd && c.cb[i]->stale >=Tavgstale_cD) keep[i] = 0; else { keep[i] = 1; keepCnt += 1; } } code_element **foo = new code_element* [keepCnt]; int k=0; for(int ii=0; ii<c.numEntries; ii++) { if(keep[ii]) { foo[k] = c.cb[ii]; k++; } } delete [] keep; delete [] c.cb; c.cb = foo; int numCleared = c.numEntries - keepCnt; c.numEntries = keepCnt; return(numCleared); } int cD_to_cC(codeBook &d, codeBook &c, int FrmNum) { int *keep_d = new int [d.numEntries]; int keepCnt = 0; for(int i=0; i<d.numEntries; i++) { int convertThresh = (FrmNum - T)/d.cb[i]->f; if(d.cb[i]->f >=Fadd && convertThresh <=Tavgstale) { keep_d[i] = 0; } else { keep_d[i] = 1; keepCnt += 1; } } code_element **foo_d = new code_element* [keepCnt]; int k=0; for(int ii=0; ii<d.numEntries; ii++) { if(keep_d[ii]) { foo_d[k] = d.cb[ii]; k++; } else { code_element **foo_c = new code_element* [c.numEntries+1]; for(int jj=0; jj<c.numEntries; jj++) { foo_c[jj] = c.cb[jj]; } foo_c[c.numEntries] = new code_element; delete [] c.cb; c.cb = foo_c; c.cb[c.numEntries] = d.cb[ii]; c.numEntries +=1; } } delete [] keep_d; delete [] d.cb; d.cb = foo_d; int numconverted = d.numEntries - keepCnt; d.numEntries = keepCnt; return(numconverted); } ``` 下面是报错: 1>------ 已启动生成: 项目: Realtime_online_cb_det, 配置: Debug x64 ------ 1> Realtime_online_cb_det.cpp 1>Realtime_online_cb_det.cpp(185): error C2065: “CvBGStatModel”: 未声明的标识符 1>Realtime_online_cb_det.cpp(185): error C2065: “bg_model”: 未声明的标识符 1>Realtime_online_cb_det.cpp(186): error C2065: “CvBGStatModel”: 未声明的标识符 1>Realtime_online_cb_det.cpp(186): error C2065: “bg_model1”: 未声明的标识符 1>Realtime_online_cb_det.cpp(271): error C2065: “bg_model”: 未声明的标识符 1>Realtime_online_cb_det.cpp(271): error C3861: “cvCreateGaussianBGModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(272): error C2065: “bg_model1”: 未声明的标识符 1>Realtime_online_cb_det.cpp(272): error C3861: “cvCreateFGDStatModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(308): error C3861: “cvChangeDetection”: 找不到标识符 1>Realtime_online_cb_det.cpp(309): error C3861: “cvChangeDetection”: 找不到标识符 1>Realtime_online_cb_det.cpp(315): error C2065: “bg_model”: 未声明的标识符 1>Realtime_online_cb_det.cpp(315): error C3861: “cvUpdateBGStatModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(316): error C2065: “bg_model1”: 未声明的标识符 1>Realtime_online_cb_det.cpp(316): error C3861: “cvUpdateBGStatModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(381): error C2065: “bg_model1”: 未声明的标识符 1>Realtime_online_cb_det.cpp(381): error C2227: “->foreground”的左边必须指向类/结构/联合/泛型类型 1> 类型是“unknown-type” 1>Realtime_online_cb_det.cpp(381): error C2227: “->origin”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(382): error C2065: “bg_model”: 未声明的标识符 1>Realtime_online_cb_det.cpp(382): error C2227: “->foreground”的左边必须指向类/结构/联合/泛型类型 1> 类型是“unknown-type” 1>Realtime_online_cb_det.cpp(382): error C2227: “->origin”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(391): error C2065: “bg_model”: 未声明的标识符 1>Realtime_online_cb_det.cpp(391): error C2227: “->foreground”的左边必须指向类/结构/联合/泛型类型 1> 类型是“unknown-type” 1>Realtime_online_cb_det.cpp(391): error C2660: “cvShowImage”: 函数不接受 1 个参数 1>Realtime_online_cb_det.cpp(396): error C2065: “bg_model1”: 未声明的标识符 1>Realtime_online_cb_det.cpp(396): error C2227: “->foreground”的左边必须指向类/结构/联合/泛型类型 1> 类型是“unknown-type” 1>Realtime_online_cb_det.cpp(396): error C2660: “cvShowImage”: 函数不接受 1 个参数 1>Realtime_online_cb_det.cpp(529): error C2065: “CvBGStatModel”: 未声明的标识符 1>Realtime_online_cb_det.cpp(529): error C2059: 语法错误:“)” 1>Realtime_online_cb_det.cpp(530): error C2065: “CvBGStatModel”: 未声明的标识符 1>Realtime_online_cb_det.cpp(530): error C2059: 语法错误:“)” 1>Realtime_online_cb_det.cpp(529): error C3861: “cvReleaseBGStatModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(530): error C3861: “cvReleaseBGStatModel”: 找不到标识符 1>Realtime_online_cb_det.cpp(677): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(712): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(714): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(714): error C2227: “->learnHigh”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(714): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(715): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(715): error C2227: “->learnLow”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(715): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(717): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(789): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(799): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(801): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(802): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(803): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(804): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(805): error C2065: “n”: 未声明的标识符 1>Realtime_online_cb_det.cpp(824): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(824): error C2227: “->learnHigh”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(825): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(825): error C2227: “->learnLow”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(827): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(880): warning C4244: “=”: 从“float”转换到“int”,可能丢失数据 1>Realtime_online_cb_det.cpp(882): warning C4244: “=”: 从“float”转换到“int”,可能丢失数据 1>Realtime_online_cb_det.cpp(938): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(962): warning C4244: “=”: 从“float”转换到“int”,可能丢失数据 1>Realtime_online_cb_det.cpp(964): warning C4244: “=”: 从“float”转换到“int”,可能丢失数据 1>Realtime_online_cb_det.cpp(1024): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(1061): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(1061): error C2227: “->learnHigh”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(1062): error C2065: “i”: 未声明的标识符 1>Realtime_online_cb_det.cpp(1062): error C2227: “->learnLow”的左边必须指向类/结构/联合/泛型类型 1>Realtime_online_cb_det.cpp(1064): error C2065: “i”: 未声明的标识符 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
windows 重叠IO 命名管道程序疑问?
我写了一个命名管道通信例子,但是现在有两个疑问? 疑问1 : 为什么我的程序只能由客户端向服务器发送数据,服务端不能向客户端发送数据呢?服务端显示发送成功,但是客户端相应的可读事件不能被触发。 疑问2 : 偶尔出现客户端向服务器发送数据的时候 前一两个包丢失。 服务端代码: ``` #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <tchar.h> #include <strsafe.h> #define CONNECTING_STATE 3 #define READING_STATE 1 #define WRITING_STATE 2 #define INSTANCES 1 #define PIPE_TIMEOUT 5000 #define BUFSIZE 4096 typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; } PIPEINST, *LPPIPEINST; VOID DisconnectAndReconnect(DWORD); BOOL ConnectToNewClient(HANDLE, LPOVERLAPPED); bool PostRecvRequest(LPPIPEINST hInst) { if (NULL == hInst) return false; char buf[1] = {0}; DWORD dwBytesReaded = 0; if (!ReadFile(hInst->hPipeInst, buf, 1, &dwBytesReaded, &hInst->oOverlap)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) { printf("client ReadFile error : %d \n", err); return false; } } return true; } bool IsNamedPipeCanRecv(LPPIPEINST hInst) { if (NULL == hInst) return false; if (WAIT_OBJECT_0 ==WaitForSingleObject(hInst->oOverlap.hEvent, INFINITE)) { return true; } ResetEvent(hInst->oOverlap.hEvent); return false; } DWORD WINAPI RecvThread(LPVOID param) { LPPIPEINST hInst = (LPPIPEINST) param; if (hInst) { while(1) { if (IsNamedPipeCanRecv(hInst)) { char buf[1024] = {0}; DWORD dwBytesReaded = 0; ReadFile(hInst->hPipeInst, buf, 1024, &dwBytesReaded, NULL); printf("Server recv : %s\n", buf); } PostRecvRequest(hInst); } } return 0; } PIPEINST Pipe[INSTANCES]; HANDLE hEvents[INSTANCES]; int _tmain(int argc, _TCHAR* argv[]) { LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe"); for (int i = 0; i < INSTANCES; i++) { // Create an event object for this instance. hEvents[i] = CreateEvent( NULL, // default security attribute TRUE, // manual-reset event TRUE, // initial state = signaled NULL); // unnamed event object if (hEvents[i] == NULL) { printf("CreateEvent failed with %d.\n", GetLastError()); return 0; } Pipe[i].oOverlap.hEvent = hEvents[i]; Pipe[i].hPipeInst = CreateNamedPipe( lpszPipename, // pipe name PIPE_ACCESS_DUPLEX | // read/write access FILE_FLAG_OVERLAPPED, // overlapped mode PIPE_TYPE_MESSAGE | // message-type pipe PIPE_READMODE_MESSAGE | // message-read mode PIPE_WAIT, // blocking mode INSTANCES, // number of instances BUFSIZE*sizeof(TCHAR), // output buffer size BUFSIZE*sizeof(TCHAR), // input buffer size PIPE_TIMEOUT, // client time-out NULL); // default security attributes if (Pipe[i].hPipeInst == INVALID_HANDLE_VALUE) { printf("CreateNamedPipe failed with %d.\n", GetLastError()); return 0; } ConnectToNewClient( Pipe[i].hPipeInst, &Pipe[i].oOverlap); } HANDLE hThread = CreateThread(0, 0, RecvThread, &Pipe[0], 0, 0); while (1) { char buf[1024]; scanf("%s", buf); DWORD dw; BOOL b = WriteFile(Pipe[0].hPipeInst, buf, strlen(buf), &dw, &Pipe[0].oOverlap); printf("send(%d:%d) : %s\n", dw, b, buf); } return 0; } VOID DisconnectAndReconnect(DWORD i) { // Disconnect the pipe instance. if (! DisconnectNamedPipe(Pipe[i].hPipeInst) ) { printf("DisconnectNamedPipe failed with %d.\n", GetLastError()); } // Call a subroutine to connect to the new client. ConnectToNewClient( Pipe[i].hPipeInst, &Pipe[i].oOverlap); } BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo) { BOOL fConnected, fPendingIO = FALSE; // Start an overlapped connection for this pipe instance. fConnected = ConnectNamedPipe(hPipe, lpo); // Overlapped ConnectNamedPipe should return zero. if (fConnected) { printf("ConnectNamedPipe failed with %d.\n", GetLastError()); return 0; } switch (GetLastError()) { // The overlapped connection in progress. case ERROR_IO_PENDING: fPendingIO = TRUE; break; // Client is already connected, so signal an event. case ERROR_PIPE_CONNECTED: if (SetEvent(lpo->hEvent)) break; // If an error occurs during the connect operation... default: { printf("ConnectNamedPipe failed with %d.\n", GetLastError()); return 0; } } return fPendingIO; } ``` 客户端代码 ``` #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <conio.h> #include <tchar.h> #define BUFSIZE 512 typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; } PIPEINST, *LPPIPEINST; bool PostRecvRequest(LPPIPEINST hInst) { if (NULL == hInst) return false; char buf[1] = {0}; DWORD dwBytesReaded = 0; if (!ReadFile(hInst->hPipeInst, buf, 1, &dwBytesReaded, &hInst->oOverlap)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) { // 109 管道已结束 printf("client ReadFile error : %d \n", err); return false; } } return true; } bool IsNamedPipeCanRecv(LPPIPEINST hInst) { if (NULL == hInst) return false; if (WAIT_OBJECT_0 ==WaitForSingleObject(hInst->oOverlap.hEvent, INFINITE)) { return true; } ResetEvent(hInst->oOverlap.hEvent); return false; } DWORD WINAPI RecvThread(LPVOID param) { LPPIPEINST hInst = (LPPIPEINST) param; if (hInst) { while(1) { if (IsNamedPipeCanRecv(hInst)) { char buf[1024] = {0}; DWORD dwBytesReaded = 0; ReadFile(hInst->hPipeInst, buf, 1024, &dwBytesReaded, NULL); printf("Client recv : %s\n", buf); } PostRecvRequest(hInst); } } return 0; } int _tmain(int argc, _TCHAR* argv[]) { PIPEINST Pipe; Pipe.oOverlap.hEvent = CreateEvent( NULL, // default security attribute TRUE, // manual-reset event FALSE, // initial state = signaled NULL); // unnamed event object LPTSTR lpvMessage=TEXT("Default message from client."); BOOL fSuccess = FALSE; DWORD dwMode; LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe"); if( argc > 1 ) lpvMessage = argv[1]; // Try to open a named pipe; wait for it, if necessary. while (1) { Pipe.hPipeInst = CreateFile( lpszPipename, // pipe name GENERIC_READ | GENERIC_WRITE, // read and write access 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe FILE_FLAG_OVERLAPPED, // default attributes NULL); // no template file // Break if the pipe handle is valid. if ( Pipe.hPipeInst != INVALID_HANDLE_VALUE) break; // Exit if an error other than ERROR_PIPE_BUSY occurs. if (GetLastError() != ERROR_PIPE_BUSY) { _tprintf( TEXT("Could not open pipe. GLE=%d\n"), GetLastError() ); return -1; } // All pipe instances are busy, so wait for 20 seconds. if ( ! WaitNamedPipe(lpszPipename, 20000)) { printf("Could not open pipe: 20 second wait timed out."); return -1; } } // The pipe connected; change to message-read mode. dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT; fSuccess = SetNamedPipeHandleState( Pipe.hPipeInst, // pipe handle &dwMode, // new pipe mode NULL, // don't set maximum bytes NULL); // don't set maximum time if ( ! fSuccess) { _tprintf( TEXT("SetNamedPipeHandleState failed. GLE=%d\n"), GetLastError() ); return -1; } // Send a message to the pipe server. PostRecvRequest(&Pipe); HANDLE hThread = CreateThread(0, 0, RecvThread, &Pipe, 0, 0); while (1) { char buf[1024]; scanf("%s", buf); DWORD dw; WriteFile(Pipe.hPipeInst, buf, strlen(buf), &dw, NULL); printf("send(%d) : %s\n", dw, buf); } return 0; } ```
c语言疑似递归与循环小数丢失问题
首先是题目: 问题描述 用递归方法求数列1/3+2/5+3/7+4/9+5/11+6/13+......的和 输入格式 一个正整数n 输出格式 上述数列前n项的和,保留15位小数 样例输入 200 样例输出 98.683296008649080 然后是递归代码: #include<stdio.h> double tg(double d); int main() { double n; scanf("%lf",&n); printf("%.15f\n",tg(n)); } double tg(double d) { if (d<2) return 1./3; else return tg(d-1)+d/(2*d+1); } 而后是循环代码: #include <stdio.h> double a(double n); int main() { int c; double e,d; c=1; e=0; scanf("%lf",&d); for(c=1;c<=d;c++) { e=e+a(c); } printf("%.15lf",e); } double a(double n) { double b; b=n/ (2*n+1); return b; } 输入200 测试结果 递归:98.683296008649094 递推:98.683296008649080 可是我定义数据类型中并没有区别 为何答案会有区别??
使用信号机制捕捉异步IO时,出现个别IO信号丢失
首先我简单描述一下问题: 我编写了一个程序,来完成文件的拷贝功能。 首先从目标文件读取数据块,然后使用异步写操作写入另外一个文件中。 为了可以捕获每一次写操作的完结时间,我使用了信号机制。当异步写操作结束时,调用HandleIOResult函数进行处理。 现在的问题是:在捕获信号的过程中,会出现捕获的信号个数少于发送的信号个数。 而当我在每一次异步写之前添加usleep以后,则不会出现这种情况,即所有的信号都可以正确的捕获到。 求大神给看看到底是什么问题,应该怎么解决呢? 下面是代码: 有几点需要说明一下: 1、每次读取和写入的文件数据块大小是一样的,都是OBJ_PER_SIZE,总共读取和写入的个数为OBJ_MAX_NUM 2、数组arr_obj_mem主要用来记录每一个文件数据块的相关信息,以及它们写操作的开始和结束时间 ``` #include <stdio.h> #include <fcntl.h> #include <string.h> #include <pthread.h> #include <list> #include <aio.h> #include <stdint.h> #include <sys/time.h> #include <unistd.h> #define OBJ_PER_SIZE 65536 //64KB per obj #define OBJ_MAX_NUM 10000 const char* file_read = "read.txt"; const char* file_write = "write.txt"; int fd_write = 0; int remained_obj_num = 0; int total_obj_num = 0; int write_ops_num = 0; int signal_get_num = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t finish = PTHREAD_COND_INITIALIZER; struct obj_info { char* data; uint32_t obj_id; int data_size; int primary_dir_id; uint32_t offset_dir; uint64_t offset_space; double write_start_time; double write_end_time; double log_start_time; double log_end_time; double sync_start_time; double sync_end_time; bool finished; }; struct obj_info arr_obj_mem[OBJ_MAX_NUM]; struct SigData { int type; //1 for write int data_id; //match with arr_obj_mem struct aiocb64* aio_req; }; struct aiocb64 arr_aio_write[OBJ_MAX_NUM]; struct sigaction sig_act_write[OBJ_MAX_NUM]; struct SigData arr_write_data[OBJ_MAX_NUM]; double GetMstime(void) { struct timeval curr_time; gettimeofday(&curr_time, NULL); return (curr_time.tv_sec * 1000.0 + curr_time.tv_usec / 1000.0); } bool AllFinished () { int i; for(i=0;i<total_obj_num;i++) { if(!arr_obj_mem[i].finished) return false; } return true; } void HandleIOResult(int signo, siginfo_t *info, void* context) { struct SigData *req; int ret = 0; signal_get_num++; if(info->si_signo == SIGIO) { req = (SigData*)info->si_value.sival_ptr; if(req->type == 1) { //handle write operations if(aio_error64(req->aio_req) == 0) { ret = aio_return64(req->aio_req); int obj_id = req->data_id; if(write_ops_num >= remained_obj_num) { pthread_cond_signal(&finish); } } } } } void DoWriteAndLog(int obj_id) { int ret = 0; sigemptyset(&sig_act_write[obj_id].sa_mask); sig_act_write[obj_id].sa_flags = SA_SIGINFO; sig_act_write[obj_id].sa_sigaction = HandleIOResult; bzero( (char *)&arr_aio_write[obj_id], sizeof(struct aiocb64) ); arr_aio_write[obj_id].aio_buf = arr_obj_mem[obj_id].data; arr_aio_write[obj_id].aio_fildes = fd_write; arr_aio_write[obj_id].aio_nbytes = arr_obj_mem[obj_id].data_size; arr_aio_write[obj_id].aio_offset = arr_obj_mem[obj_id].offset_space; arr_aio_write[obj_id].aio_sigevent.sigev_notify = SIGEV_SIGNAL; arr_aio_write[obj_id].aio_sigevent.sigev_signo = SIGIO; arr_write_data[obj_id].type = 1; arr_write_data[obj_id].data_id = obj_id; arr_write_data[obj_id].aio_req = &arr_aio_write[obj_id]; sigaction(SIGIO, &sig_act_write[obj_id], NULL); arr_obj_mem[obj_id].write_start_time = GetMstime(); ret = aio_write64(&arr_aio_write[obj_id]); write_ops_num++; if(ret != 0) printf("aio_write64 error \n"); } void ReadAndWrite () { fd_write = open(file_write, O_CREAT | O_WRONLY); if(fd_write < 0) { printf("open file %s failed!\n", file_write); return ; } int fd_read = open(file_read, O_RDONLY); if(fd_read < 0) { printf("open file %s failed\n", file_read); return ; } int i = 0; uint64_t offset = 0; int ret = 0; printf("start to read file %s!\n", file_read); while(true) { if(i >= OBJ_MAX_NUM) arr_obj_mem[i].data = new char[OBJ_PER_SIZE + 1]; ret = pread(fd_read, arr_obj_mem[i].data, OBJ_PER_SIZE, offset); if(ret < 0) { printf("read file %s failed!\n", file_read); return ; } if(ret == 0) { printf("read zero bytes!\n"); arr_obj_mem[i].obj_id = i; arr_obj_mem[i].data_size = ret; arr_obj_mem[i].offset_space = offset; DoWriteAndLog(i); offset += ret; i++; pthread_mutex_lock(&mutex); remained_obj_num++; pthread_mutex_unlock(&mutex); total_obj_num++; if(ret != OBJ_PER_SIZE) { break; } } } double total_write_time = 0; void ResultCount() { int i; for(i=0;i<total_obj_num;i++) { if(arr_obj_mem[i].finished) { total_write_time += (arr_obj_mem[i].write_end_time - arr_obj_mem[i].write_start_time); } } printf("total_write_time = %.2f\n", total_write_time); } int main(int argc, char **argv) { ReadAndWrite(); pthread_mutex_lock(&mutex); while(!AllFinished()) { pthread_cond_wait(&finish, &mutex); } pthread_mutex_unlock(&mutex); printf("All Job Done!\n"); ResultCount(); return 0; } ```
InputStream 乱码问题
package ioliu; import java.io.*; public class TestInputStream { public static void main(String[] args) throws Exception{ InputStream is = new FileInputStream("D:\\xunlei\\TestSocket.txt");//字节流 int ch; ch = is.read();//从输入流中读取数据的下一个字节。 while(-1 != is.read()) { System.out.printf("%c", ch); ch = is.read(); is.close(); } /*出现丢失,乱码 * ipr aai.; motjv.e.; ulccasTsSce ulcsai odmi(tig]ag)trw xeto,IEcpin{ okts e okt"2..."66) OtuSra s=s.eOtuSra(; aaupttemds=nwDtOtuSra(s; o.rtUF"el,evr)/×?? §??? o.ls(; o.ls(; tcoe) } */ import java.io.*; //这样能正确读出来,这是为什么 public class TestInputStream { public static void main(String[] args) throws Exception{ InputStream is = new FileInputStream("D:\\xunlei\\TestSocket.txt");//字节流 //byte[] b=new byte[1000]; //创建合适文件大小的字节数组 is.read(b); //读取文件中的内容到b[]数组 is.close(); System.out.println(new String(b)); } } /* import java.io.*; import java.net.*; public class TestSocket { public static void main(String[] args) throws Exception, IOException { Socket st = new Socket("127.0.0.1",6666); OutputStream os = st.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeUTF("hello,server");//阻塞式 效率较低 dos.flush(); dos.close(); st.close(); } } */
在中国程序员是青春饭吗?
今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...
《MySQL 性能优化》之理解 MySQL 体系结构
本文介绍 MySQL 的体系结构,包括物理结构、逻辑结构以及插件式存储引擎。
【资源】一个C/C++开发工程师的学习路线(已经无路可退,唯有逆风飞翔)【内附资源页】
声明: 1)该文章整理自网上的大牛和专家无私奉献的资料,具体引用的资料请看参考文献。 2)本文仅供学术交流,非商用。所以每一部分具体的参考资料并没有详细对应。如果某部分不小心侵犯了大家的利益,还望海涵,并联系博主删除。 3)博主才疏学浅,文中如有不当之处,请各位指出,共同进步,谢谢。 4)此属于第一版本,若有错误,还需继续修正与增删。还望大家多多指点。大家都共享一点点,一起为祖国科研的推进...
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
20道你必须要背会的微服务面试题,面试一定会被问到
写在前面: 在学习springcloud之前大家一定要先了解下,常见的面试题有那块,然后我们带着问题去学习这个微服务技术,那么就会更加理解springcloud技术。如果你已经学了springcloud,那么在准备面试的时候,一定要看看看这些面试题。 文章目录1、什么是微服务?2、微服务之间是如何通讯的?3、springcloud 与dubbo有哪些区别?4、请谈谈对SpringBoot 和S...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
2020 年,大火的 Python 和 JavaScript 是否会被取而代之?
Python 和 JavaScript 是目前最火的两大编程语言,但是2020 年,什么编程语言将会取而代之呢? 作者 |Richard Kenneth Eng 译者 |明明如月,责编 | 郭芮 出品 | CSDN(ID:CSDNnews) 以下为译文: Python 和 JavaScript 是目前最火的两大编程语言。然而,他们不可能永远屹立不倒。最终,必将像其他编程语言一...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
神级宝库!GitHub 标星 1.2w+,Chrome 最天秀的插件都在这里啦!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个沉迷 Chrome 不能自拔的蒟蒻… 作为一个在远古时代用过什么 IE、360、猎豹等浏览器的资深器哥,当我第一次了解 Chrome 的时候,就被它的美貌给吸引住了… 就在我用了一段时间之后,我坚决的卸载了电脑上其它碍眼的浏览器,并觉得在之前的搬砖生涯中,我不配当哥,我只配是个沙雕… ...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
张朝阳回应迟到 1 分钟罚 500:资本家就得剥削员工
loonggg读完需要2分钟速读仅需 1 分钟大家我,我是你们的校长。前几天,搜狐的董事局主席兼 CEO 张朝阳和搜狐都上热搜了。原因很简单,就是搜狐出了“考勤新规”。一封搜狐对员工发布...
一个程序在计算机中是如何运行的?超级干货!!!
强烈声明:本文很干,请自备茶水!???? 开门见山,咱不说废话! 你有没有想过,你写的程序,是如何在计算机中运行的吗?比如我们搞Java的,肯定写过这段代码 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } ...
【蘑菇街技术部年会】程序员与女神共舞,鼻血再次没止住。(文末内推)
蘑菇街技术部的年会,别开生面,一样全是美女。
立即提问