gpt4 book ai didi

C程序可以编译但不能运行

转载 作者:行者123 更新时间:2023-11-30 19:27:19 25 4
gpt4 key购买 nike

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

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

执行“D:\Compterprogramming\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 */


}

最佳答案

在这个windows文件路径D:\Compterprogramming\Project\cass.exe”中,似乎有一个空格

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

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

关于C程序可以编译但不能运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55879284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com