我想问为什么GCC编译我的C代码,虽然它有错误,MSVS注意到。我已经找到解决这些错误的解决方案。但我想知道,为什么海湾合作委员会没有看到他们。这里是我的代码:GCC VS MSVS编译器
#define _USE_MATH_DEFINES
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
double randomer(double randitude)
{
double random;
if(randitude != 0)
{
int integerranditude = randitude*1000000;
int base = rand()%integerranditude;
random = (2*(base/1000000.0)) - randitude;
printf("%lf\n", random);
}
else
{
random = 0.0;
}
return random;
}
void counttofile(double x, double period, double expression, double amplitude, double random, double randitude)
{
FILE* wyniki = fopen("wyniki.txt", "wt");
for(x = 0; x <= period*M_PI*2; x = x + 0.128)
{
random = randomer(randitude);
expression = amplitude*(sin(x) + cos(x)) + random;
fprintf(wyniki, "(%lf) = %lf\n", x, expression);
/*expression = sin(x) + cos(x) + random;
if(fabs(expression) <= fabs(amplitude))
{
fprintf(wyniki, "(%lf) = %lf\n", x, expression);
}
else
{
fprintf(wyniki, "(%lf) = poza zakresem\n", x);
}*/
}
fclose(wyniki);
}
void unitchange(double period, double amplitude)
{
period = period * 180/M_PI;
amplitude = amplitude * 180/M_PI;
}
int main(void)
{
srand (time(NULL));
double x, period, expression, amplitude, randitude, random;
random = 0;
int command;
x = 0;
printf("Co chciałbyś zrobić? \n1. wygenerowac wartosci funkcji sin(x) + cos(x)\n");
printf("2. wygenerowac wartosci funkcji sin(x) + cos(x),\n a nastepnie zaszumic o wskazana amplitude.\n");
printf("Wpisz numer zadania: ");
scanf("%d", &command);
if(command == 1)
{
randitude = 0;
printf("Podam wyniki dzialania sin(x) + cos(x).\nOkresl w jakim zakresie amplitudy mam podac wyniki: ");
scanf("%lf", &litude);
expression = sin(x) + cos(x);
printf("\nIle okresow mam policzyc? ");
scanf("%lf", &period);
unitchange(period, amplitude);
counttofile(x, period, expression, amplitude, random, randitude);
}
else if(command == 2)
{
printf("Podam wyniki dzialania sin(x) + cos(x), zaszumionego o zadana amplitude.\nOkresl w jakim zakresie amplitudy mam podac wyniki: ");
scanf("%lf", &litude);
expression = sin(x) + cos(x);
printf("\nIle okresow mam policzyc? ");
scanf("%lf", &period);
printf("Amplituda szumu ma wynosić: ");
scanf("%lf", &randitude);
unitchange(period, amplitude);
counttofile(x, period, expression, amplitude, random, randitude);
}
else
{
printf("\nNieprawidlowy numer polecenia. Sprobuj jeszcze raz.");
}
int proba = 0;
for(proba =0; proba <=10; proba ++)
{
randomer(randitude);
}
return 0;
}
感谢您的帮助。
发布特定错误消息 – alrikai
可能有帮助啊,我在声明后看到声明。也许你的问题是微软编译器不支持C99。 MSVS卡在黑暗时代,gcc不是。 –