C程序编译但不运行

问题描述 投票:-1回答:1

我已经编写了一个分配程序,它符合但不执行。我已经尝试为代码创建新文件,但这没有帮助。在过去工作的时候,一半的项目会起作用,但文件访问部分却没有用。

这是我执行程序时出现的错误:

无法执行“D:\ Compter programming \ Project \ cass.exe”:错误193:%1不是有效的Win32应用程序。

这是代码:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

const int SIZE = 18;                                                                /* This is seting up the size of the array called SIZE, the code will use this rather than using a number */ 

void calc_freq (int[]);                                                             /* These are the function prototypes*/          
void ind(double, int[], double[]);
void cap(double, int[], double[]);
void att(double, double, int[], double[]);
void attdb(double, double, int[], double[], double[]);
void screenprint (int[], double[], double[], double[], double[]);
void fileprint (int[], double[], double[], double[], double[]);


int main (void) {
    int frequencies[SIZE], n;

    double ind_react[SIZE], cap_react[SIZE], attenuation[SIZE], attenuationdb[SIZE] ;
    double L, C;


    printf("Enter inductance in milli Henrys\n");
    scanf("%lf",&L);
    L = L / 1000;                                                                   /* Convert from milli Henies to Henries */

    printf("Enter capacitance in Farads\n");
    scanf("%lf",&C);
    C = C / 1000000;                                                                /* Converts from miro Farads to Farads */


    calc_freq (frequencies);                                                        /* function prototypes*/
    ind(L, frequencies, ind_react);
    cap(C, frequencies, cap_react);
    att(L, C, frequencies, attenuation);
    attdb(L, C, frequencies, attenuation, attenuationdb);
    screenprint (frequencies, ind_react, cap_react, attenuation, attenuationdb);
    fileprint (frequencies, ind_react, cap_react, attenuation, attenuationdb);


    return 0;

}

void calc_freq (int numbers[SIZE])                      
{
    int n;

    for (n=0; n<9; n++)
    {
        numbers[n] = 100*(n+1);                                                     /* This equation helps frequncy go up in 100s */                    

    }

    for (n=9; n<18; n++)
    {
        numbers[n] = 1000*(n-8);                                                    /* This equations helps frequency go up in 1000s */

    }
}


void ind(double L, int frequencies[], double ind_react[])
{

    int i;
    for(i=0; i<SIZE; i++)
    {
        ind_react[i] = 2*M_PI*frequencies[i]*L;                                     /* in the math library PI is M_PI */
    }
}

void cap(double C, int frequencies[], double cap_react[])
{
    int i;
    for(i=0; i<SIZE; i++)
    {
        cap_react[i] = 1/(2*M_PI*frequencies[i]*C);
    }

}

void att(double L, double C, int frequencies[], double attenuation[])
{
    int i;
    for(i=0; i<SIZE; i++)
    {
        attenuation[i] = 1/((1)-(2*M_PI*frequencies[i]*2*M_PI*frequencies[i])*L*C);             
        if (attenuation[i] <0)  
        {
        attenuation[i] = attenuation[i] * (-1);
        }
    }   

}

void attdb(double L, double C, int frequencies[], double attenuation[], double attenuationdb[])
{
    int i;
    for(i=0; i<SIZE; i++)
    {
        attenuation[i] = 1/((1)-(2*M_PI*frequencies[i]*2*M_PI*frequencies[i])*L*C);
        if (attenuation[i] <0)  
        {
        attenuation[i] = attenuation[i] * (-1);                                     /* the (-1) gets rid of the negative attenuation anwers which can't be used in the log expression */
        }

        attenuationdb[i] = 20*log10 (attenuation[i]);

    }   

} 

void screenprint (int frequencies[SIZE], double ind_react[SIZE], double cap_react[SIZE], double attenuation[SIZE], double attenuationdb[SIZE])
{
    printf("\nFREQUENCIES\tINDUCTIVE REACTANCE\tCAPACITIVE REAVTANCE\tATTENUATION\tATTENUATION (dB)\n");                /* this will put the calculated answers in a table form */
    printf("--------------------------------------------------------------------------------------------------\n"); 

    int n; 
    for (n=0; n<18; n++)
    {
    printf ("%4i\t %18.3lf\t %18.3lf\t %14.3lf\t %14.3lf\n",frequencies[n], ind_react[n], cap_react[n], attenuation[n], attenuationdb[n]);  
    }   
    /* puting a number after '%' will change the indent between each column of the table    and adding a decimal to tht number controls the number of decimal places of the values */
}

void fileprint (int frequencies[SIZE], double ind_react[SIZE], double cap_react[SIZE], double attenuation[SIZE], double attenuationdb[SIZE])
{

char filename[200];


FILE *f_ptr;                                                                        /* *f_ptr creates a file pointer */

printf("Enter the full name of the output file: ");

scanf("%s", filename);                                                              /* This line scans the file name and puts it into the filename */

/*Open the file for writing */

f_ptr = fopen(filename, "w");                                                       /* "w" for write mode */
int n; 
    for (n=0; n<18; n++)
{
fprintf (f_ptr,"%4i\t %18.3lf\t %18.3lf\t %14.3lf\t %14.3lf\n",frequencies[n], ind_react[n], cap_react[n], attenuation[n], attenuationdb[n]);
}

fclose(f_ptr);                                                                      /* Close the file */


}
c makefile dev-c++
1个回答
0
投票

在这个Windows文件路径D:\ Compter programming \ Project \ cass.exe“中,似乎有一个空格。

因此,它可能无法检测应用程序类型。

该链接有解释。 https://support.symantec.com/en_US/article.TECH11171.html

© www.soinside.com 2019 - 2024. All rights reserved.