C程序可编译但无法运行

时间:2019-04-27 09:51:49

标签: c makefile dev-c++

我已经为作业编写了一个程序,它可以执行但不能执行。我尝试为该代码创建新文件,但这没有帮助。过去,当它工作时,一半的项目可以工作,但其中的文件访问部分却无法工作。

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

无法执行“ 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 */


}

1 个答案:

答案 0 :(得分:0)

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

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

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