我一直在試圖運行我的代碼,但總是與錯誤代碼0000005計劃與0000005
#include <stdio.h>
#include <math.h>
void calculate_resistance(char metal, int length, int diameter, float resistivity);
int main()
{
int length, diameter;
float resistivity;
char metal;
printf("Enter the name of the metal: ");
scanf("%s", &metal);
printf("Enter the resistivity: ");
scanf("%f", &resistivity);
printf("Enter the length: ");
scanf("%d", &length);
printf("Enter the diameter: ");
scanf("%d", &diameter);
calculate_resistance(metal, length, diameter, resistivity);
return 0;
}
void calculate_resistance(char metal, int length, int diameter, float resistivity)
{
float radius = diameter/2;
float area_of_wire = (M_PI) * pow(radius,2) * length;
float resistance = resistivity * length/area_of_wire;
printf("Resistivity of %s is %f", metal, resistance);
}
我發現,如果我註釋掉的「printf(」%S的電阻率是%F結束」,金屬崩潰, 抵抗性);」或在最後一次scanf後的任何printf它不會崩潰與錯誤代碼0xC0000005
'char metal;' - >'char metal [96];'(適當大小),'void calculate_resistance(char metal [],' – BLUEPIXY