for循环为什么没有执行
一个卷积程序,cov函数里的for循环为什么没有运行呢?
运行结果如下,只有第一个printf执行了,for循环里的printf都没有执行
The function has done
work done!
Process returned 0 (0x0) execution time : 0.053 s
Press any key to continue.
The function has done
#include<stdio.h>
#include<stdlib.h>
const int height1 = 125;
const int width1 = 80;
const int height2 = 100;
const int width2 = 100;
// 根据题目要求,设定数据的行数和列数
/*
resource 读入数据指针
result 结果数据指针
rh 读入数据的行数
rw 读入数据的列数
temp 模版数据指针
temph 模版数据的行数
tempw 模版数据的列数
void cov(int *resource,int *result,int rh,int rw,int *temp,int temph,int tempw)函数计算卷积结果,无返回值。
*/
void cov(int *resource,int *result,int rh,int rw,int *temp,int temph,int tempw)
{
int i,j,k,l;
printf("The function has done\n");//test
//计算数据过程中中,当所剩下的行数和列数小于模版窗口的行数和列数时就停止计算。
for(i=0; (rh-i) < temph; i++)
{printf("The function1 has done\n");//test
for(j=0;(rw-j)<tempw;j++)
{printf("The function2 has done\n");
int res=0;
//进行一次卷积计算所得到的的结果,初始值记为零。
for(k=0;k<temph;k++)
{printf("The function3 has done\n");
for(l=0;l<tempw;l++)
{printf("The function4 has done\n");
res+=resource[(i+k)*rw+j+l]*temp[l*tempw+k];
//计算卷积结果
printf("%d",res);
}
}
result[(i+1)*rw+j+1]=res;
//将计算结果赋给结果数组
}
}
}
//main 函数
int main(void)
{
FILE *data,*result1,*result2;
//data 原始数据文件指针
//result1 第一次计算结果保存的数据文件指针
//result2 第二次计算结果保存的数据文件指针
int resource[10000],result[10000];
// 读入数据存放在resource所指的数组中
// 计算结果存放在result所指的数组中
int temp1[9]={0,-1,0,-1,5,-1,0,-1,0};
int temp2[25]={0,0,-1,0,0,0,-1,-2,-1,0,-1,-2,16,-2,-1,0,-1,-2,-1,0,0,0,-1,0,0};
// 根据题目要求,设定模版
int box;
// 每读进一个数,暂时存于box中
data=fopen("SourceData.txt","r");
if(data==NULL)
{
printf("can not open this file!\n");
exit(0);
}
//检验数据文件是否成功打开
result1=fopen("result1.txt","w");
result2=fopen("result2.txt","w");
//建立两个结果文件
//将数据读入resource中,并且将result初始化。
int i;
for(i=0;i<10000;i++)
{
fscanf(data,"%d",&box);
resource[i]=box;
}
//先将数据理解为125*80,模版1(temp1)进行卷积运算。
cov(resource,result,height1,width1,temp1,3,3);
//将卷积运算的结果存入result1文件中,并关闭result1指针。
for(i=0;i<10000;i++)
{
fprintf(result1,"%6d",result[i]);
}
if(fclose(result1))
printf("Can't close this file.\n");
//将数据理解为100*100,用模版2(temp2)进行卷积运算。
cov(resource,result,height2,width2,temp2,5,5);
//将运算结果存入result2文件中,并关闭result2指针。
for(i=0;i<10000;i++)
{
fprintf(result2,"%6d",result[i]);
}
if(fclose(result2) || fclose(data))
printf("Dont't close this file.\n");
//关闭data文件指针
printf("work done!");
return 0;
}
运行结果如下,只有第一个printf执行了,for循环里的printf都没有执行
The function has done
work done!
Process returned 0 (0x0) execution time : 0.053 s
Press any key to continue.
The function has done
...全文
相关推荐
js代码-帮忙看看这个代码为什么没有进入死循环
js代码-帮忙看看这个代码为什么没有进入死循环
浅谈js for循环输出i为同一值的问题
下面小编就为大家带来一篇浅谈js for循环输出i为同一值的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
基于c的for循环中改变变量值的问题
本篇文章是对c语言的for循环中改变变量值的问题进行了详细的分析介绍,需要的朋友参考下
其它循环结构PPT学习教案.pptx
其它循环结构PPT学习教案.pptx
Golang常见错误之值拷贝和for循环中的单一变量详解
主要给大家介绍了关于Golang常见错误之值拷贝和for循环中单一变量的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。


