本文介绍了救命!程序不写入文本文件,而是在命令提示符下打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨!我的程序用于计算数组中的最高频率,当我运行它时,它显示x并且没有出现的次数,但不知何故,这些行不会打印到文本文件中。请帮忙! if ((histogramw = fopen( histogram.txt, w))== NULL) { printf( 无法打开%s \ n, histogram.txt); 退出(EXIT_FAILURE); } for (i = 0 ; i< totalsize; i ++) {x = diff [i]; for (j = 0 ; j< totalsize; j ++) { if (x == diff [j]) {frequency = frequency + 1;} if (fmod(diff [j],x)== 0 ) {frequency = frequency + 1;} } if (频率> 4) / * 仅在频率大于1时打印到文件,以减少计算时间* / { fprintf(histogramw, %lf%d \ n,x,frequency); printf( %lf%d \ n,x,frequency); } frequency = 0 ; } fclose(histogramw); free(diff); 解决方案 Hi! my program is used to caluclate highest frequency in an array, when i run it, it shows x and no of times it appears, but somehow this lines are not printed into a text file. Pls help!if ((histogramw = fopen("histogram.txt", "w")) == NULL) { printf("Cannot open %s\n", "histogram.txt"); exit(EXIT_FAILURE); } for(i=0;i<totalsize;i++) { x=diff[i]; for(j=0;j<totalsize;j++) { if (x==diff[j]) {frequency=frequency+1;} if (fmod(diff[j],x)==0) {frequency=frequency+1;} } if(frequency>4) /*only print to file if frequency greater than 1, to reduce computing time*/ { fprintf(histogramw, "%lf %d\n", x, frequency); printf("%lf %d \n", x, frequency); } frequency=0; } fclose(histogramw); free(diff); 解决方案 这篇关于救命!程序不写入文本文件,而是在命令提示符下打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 00:05