C fprintf不';我什么也不写
我有以下代码:C fprintf不';我什么也不写,c,file,printf,file-handling,filehandle,C,File,Printf,File Handling,Filehandle,我有以下代码: 105 void draw_detections(char * image_file_name, image im, int num, float thresh, box *boxes, float **probs, char **names, image *labels, int classes) 106 { 107 int i; 108 FILE * fptr; 109 char filename[100]; 110 strcpy(f
105 void draw_detections(char * image_file_name, image im, int num, float thresh, box *boxes, float **probs, char **names, image *labels, int classes)
106 {
107 int i;
108 FILE * fptr;
109 char filename[100];
110 strcpy(filename,"output/");
111 strcpy(filename,image_file_name);
112 strcpy(filename, ".txt");
113 printf(filename);
115 fptr = fopen (filename, "wb");
116 printf(fptr);
118 if (fptr == NULL) {
119 fprintf(stderr, "Can't open input file in.list!\n");
120 exit(1);
122 }
123 for(i = 0; i < num; ++i){
124 int class = max_index(probs[i], classes);
125 float prob = probs[i][class];
126 if(prob > thresh){
127 //int width = pow(prob, 1./2.)*30+1;
128 int width = 8;
129 printf("%s: %.0f%%\n", names[class], prob*100);
130 fprintf(fptr, "%s,%.0f%%\n", names[class], prob*100);
一无所获!
注意:此行正确打印在标准输出上:
129 printf("%s: %.0f%%\n", names[class], prob*100);
这些线路:
110 strcpy(filename,"output/");
111 strcpy(filename,image_file_name);
112 strcpy(filename, ".txt");
是否不生成类似于output/some_name.txt的字符串
每个strcpy
调用都会覆盖目标字符串中已有的内容
使用onestrcpy
,然后使用strcat
将其他位置附加到字符串
OP:这修复了上述问题:
110 strcpy(filename,"output/");
111 strcat(filename,image_file_name);
112 strcat(filename, ".txt");
113 printf(filename);
我想你有一个
.txt
文件…看看strcpy
函数定义文件名几乎打印正确,只是它省略了文件名开头的输出/但是它甚至没有在当前目录中创建文件
110 strcpy(filename,"output/");
111 strcat(filename,image_file_name);
112 strcat(filename, ".txt");
113 printf(filename);