在TC下,float结构体型数组的问题?

程序代码如下:在vc下通过,在tc不提示"scanf : floating point formats not linked
Abnormal program termination"错误。

[quote]struct temp
{
     float data[3];
};

struct temp a[3];
int i, j;

for (i = 0; i < 3; i++)
{
     for (j = 0; j < 3; j++) 
     {
 scanf("%f",&a[i].data[j]);
      }
}[/quote]

在tc下程序不能正常输入各数组值,原因是:TC下编译环境里,如果没有浮点数的运算, 在链接时,就不会链接上浮点数链接库,所以就会出现上面的错误,在程序中加入一个关于浮点数的运算,则编译器会链接时加上这个库#include<math.h>    float x=cos(0.0);
但不能用float x=3.333*2.222,两个浮点数乘法,计算机硬件就能实现,那么编译器就不会将浮点数处理库也连入你的程序


另一个解决方法就是用临时float变量来接受用户输入,再将输入的值赋给数组,如下:
float temp;
a[i].data[j]=temp;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的C语言代码,用于在TC264上使用数组对图像进行高斯模糊: ``` #include <stdio.h> #include <stdlib.h> #include <math.h> #define WIDTH 640 #define HEIGHT 480 void gaussian_blur(unsigned char *input, unsigned char *output, int width, int height, float sigma) { int i, j, k, r; float *kernel, *p, sum; unsigned char *src, *dst; kernel = (float*)malloc((2 * r + 1) * sizeof(float)); sum = 0.0; for (i = 0; i < 2 * r + 1; i++) { kernel[i] = exp(-(i - r) * (i - r) / (2 * sigma * sigma)); sum += kernel[i]; } for (i = 0; i < 2 * r + 1; i++) { kernel[i] /= sum; } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { sum = 0.0; p = kernel; src = input + i * width + j - r; dst = output + i * width + j; for (k = 0; k < 2 * r + 1; k++) { if (j - r + k >= 0 && j - r + k < width) { sum += *p * src[k]; } p++; } *dst = (unsigned char)sum; } } free(kernel); } int main() { unsigned char *input, *output; FILE *fp; int i, j; input = (unsigned char*)malloc(WIDTH * HEIGHT * sizeof(unsigned char)); output = (unsigned char*)malloc(WIDTH * HEIGHT * sizeof(unsigned char)); fp = fopen("input.raw", "rb"); fread(input, sizeof(unsigned char), WIDTH * HEIGHT, fp); fclose(fp); gaussian_blur(input, output, WIDTH, HEIGHT, 1.0); fp = fopen("output.raw", "wb"); fwrite(output, sizeof(unsigned char), WIDTH * HEIGHT, fp); fclose(fp); free(input); free(output); return 0; } ``` 请注意,这只是一个简单的示例代码,您可能需要根据您的具体需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值