c - 将数据写入.cof 文件

标签 c fopen fwrite coff code-composer

我对编码非常陌生,并且对谷歌无法解决的问题感到完全困惑(今天第二次)。我正在 Windows 上使用 Code Composer 4 编写代码。我的代码没有错误,但 fopen("coffic.cof", "w") 根本不更改文件中的数据(并且如果文件被删除,则不会创建文件),我不能看看为什么。有什么想法吗?

#include "dsk6713_aic23.h"      //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;  //set sampling rate
# include <stdio.h>
# include <math.h>
# include <stdlib.h> 
#define pi 3.1415927
#include "coffic.cof"

void main()
{
    double hpf, fs, fco, atn, fat, tp, k, ad, m, n, o, da, db, dc;
    FILE *fp;
    int c, d, e, f, g, h, i, q, r, s, t, u, v;
    hpf = 0;            //for a high-pass filter input 1, for a low-pass filter input 0
    fs = 8000;          //input samping frequency here
    fco = 2400;         //input cut-off frequency here
    atn = 17;           //input attenuation (dB) here
    fat = 3500;         //input the frequency of attenuation here
    tp = 1/fs;
    k = tan(pi*fco*tp);
    ad = tan(pi*fat*tp);
    m = (log10((pow(10,(atn/10)))-1))/(2*(log10(ad/k)));
    o = abs(m);
    n = ceil(o);

    da = 1.414;
    c = (pow(2,15)*k*k/(1+da*k+k*k));
    d = (pow(2,15)*2*k*k/(1+da*k+k*k));
    e = (pow(2,15)*k*k/(1+da*k+k*k));
    q = (pow(2,15)*(2-2*k*k)/(1+da*k+k*k));
    r = (pow(2,15)*(-1+k-k*k)/(1+da*k+k*k));

    fp = fopen("U:\DSK6713\Ivo\CSP\coffic.cof", "w");
    if (fp == NULL)
    {
        printf("Error. Unable to open coffic.cof");
        exit(0);
    }

    fprintf(fp, "int a[3]={%d, d%, %d};\n", c, d, e);
    fprintf(fp, "int b[3]={1, d%, %d};\n", q ,r);
    fprintf(fp, "int x[3]={0,0,0};\nint y[3]={0,0,0};\n");

    fflush(fp);

    fclose(fp);

    comm_intr();                   //init DSK, codec, McBSP
    while(1);                      //infinite loop
}

interrupt void c_int11()         //interrupt service routine 
{
    short input;
    FILE *fp;
    fp = fopen("U:\DSK6713\Ivo\CSP\coffic.cof", "r");
    if (fp == NULL)
    {
        printf("Error. Unable to open coffic.cof");
        exit(0);
    }

    fclose(fp);

    x[2]=x[1];
    x[1]=x[0];
    y[2]=y[1];
    y[1]=y[0];

    input=input_sample();
    x[0]=input;

    y[0]=a[0]*x[0]+a[1]*x[1]+a[2]*x[2]+b[1]*y[1]+b[2]*x[2];     

    y[0]=y[0]>>15;                      
    input=(short)y[0];
    output_sample(input);   //output data  
    return;
}

最佳答案

fp = fopen("U:\DSK6713\Ivo\CSP\coffic.cof", "w");

不创建文件,它假定您的计算机上已有一个名为 coffic.cof 的文件。我通常在使用fopen的write函数时遇到麻烦,所以我通常使用append函数。 试试这个

fp = fopen("U:\DSK6713\Ivo\CSP\coffic.cof", "a");

我也是编程新手,但是当“w”不起作用时,这对我有用。

关于c - 将数据写入.cof 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16347811/

相关文章:

php文件写入问题

c - 如何使用 <time.h> 计算两个日期之间的天数

c - Raspberry Pi GCC Makefile 和程序结构

c - 如何编写一个简单的 Linux 设备驱动程序?

c - Thales Connect HSM - DeriveKey 操作

c - 使用 freopen 及其后的 fopen 是否合法?

c - 无法使用c打开文件

c - 无法在 C (windows) 中使用 fopen 从共享驱动器访问文件

c - fread 错误 - 段错误

php - filemtime 在文件修改前后返回相同的值