SterBlich Posted February 8, 2009 Share Posted February 8, 2009 #include <stdio.h> typedef struct { int tempo; float temperatura; }TT_PAIR; main(void) { int n_med; TT_PAIR *medidas; medidas=leitura_medidas(&n_med); /* 12. previous implicit declaration of 'leitura_medidas' was here */ dados(medidas, n_med); /* 13. previous implicit declaration of 'dados' was here */ } TT_PAIR* leitura_medidas(int n_med) { /* 17 . conflicting types for 'leitura_medidas' */ int i; TT_PAIR *medidas; printf("introduza o numero de medidas\t"); scanf("%d", n_med); for(i=0; i<=n_med; i++) { printf("Introduza o tempo e a temperatura:/t"); scanf("%d %f", medidas.tempo, medidas.temperatura); } return medidas; } void dados(TT_PAIR *medidas, int n_med) { /* 31. conflicting types for 'dados' */ FILE *coiso; int i; coiso= fopen("Dados", "w"); for(i=0; i<=n_med; i++) fprintf(coiso, "Aos %d segundos a temperatura era de %f;", medidas.tempo, medidas.temperatura); fclose(coiso); } sorry for the programming language... Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted February 8, 2009 Veteran Share Posted February 8, 2009 (edited) Well obviously that's not C#, it's either C or C++. In any case you need to add the two function declarations before the main method : TT_PAIR* leitura_medidas(int n_med); void dados(TT_PAIR *medidas, int n_med); ... and it compiles fine as C, albeit with warnings : Line 12: C4431 missing type specifier - int assumed. Line 15: C4047 function : int differs in levels of indirection from int* Line 15: C4024 leitura_medidas : different types for formal and actual parameter 1 Line 28: C4700 unintialized local variable 'medidas' used As C++, warnings C4431 and C4047 will be treated as errors. The main function must be declared to return int, and also on the third line of the main method, you try to pass the adress of an integer as an integer, which C++ forbids. To summarize, here's what's needed in addition to the function declarations to make the code C++ - compliant : main(void) // add 'int' before 'main' medidas=leitura_medidas(&n_med) // remove the '&' here You will still get runtime errors because you don't initialize variable 'n_med' in the main method before using it, same problem with 'medidas' in the 'leitura_medidas' method. If you pay attention to compiler warnings (of course if they are enabled and at the maximum level), you should see these problems already pointed out. Edited February 8, 2009 by Dr_Asik Link to comment Share on other sites More sharing options...
0 SterBlich Posted February 8, 2009 Author Share Posted February 8, 2009 thanks Link to comment Share on other sites More sharing options...
Question
SterBlich
#include <stdio.h>
typedef struct
{
int tempo;
float temperatura;
}TT_PAIR;
main(void)
{
int n_med;
TT_PAIR *medidas;
medidas=leitura_medidas(&n_med); /* 12. previous implicit declaration of 'leitura_medidas' was here */
dados(medidas, n_med); /* 13. previous implicit declaration of 'dados' was here */
}
TT_PAIR* leitura_medidas(int n_med)
{ /* 17 . conflicting types for 'leitura_medidas' */
int i;
TT_PAIR *medidas;
printf("introduza o numero de medidas\t");
scanf("%d", n_med);
for(i=0; i<=n_med; i++)
{
printf("Introduza o tempo e a temperatura:/t");
scanf("%d %f", medidas.tempo, medidas.temperatura);
}
return medidas;
}
void dados(TT_PAIR *medidas, int n_med)
{ /* 31. conflicting types for 'dados' */
FILE *coiso;
int i;
coiso= fopen("Dados", "w");
for(i=0; i<=n_med; i++)
fprintf(coiso, "Aos %d segundos a temperatura era de %f;", medidas.tempo, medidas.temperatura);
fclose(coiso);
}
sorry for the programming language...
Link to comment
Share on other sites
2 answers to this question
Recommended Posts