Я написал программу для задания, и она соответствует, но не выполняется. Я пытался создать новые файлы для кода, но это не помогло. В прошлом, когда это работало, половина проекта работала, но часть доступа к файлам не работала.
Это ошибка, которая появляется, когда я запускаю программу:
Не удалось выполнить «D: \ Программирование на компьютере \ 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 */
}