Bartuk
June 9th, 2009, 11:25 AM
Hi there,
So i have a problem with a program i've written in C and compiled it using the standart gcc(gcc-Version 4.3.3 (Ubuntu 4.3.3-5ubuntu4))
actually i dont know if its a gcc bug or only my crappy coding skills.
so heres the complete code:
#include <stdio.h>
struct kombi
{
char bezeichnung[20];
double zet;
char atyp;
};
void show(struct kombi *kombi_ptr){
printf("Bezeichnung: %s\n",(kombi_ptr)->bezeichnung);
printf("Zet: %f\n",(kombi_ptr)->zet);
printf("Atyp: %c\n",(kombi_ptr)->atyp);
}
int main (void)
{
struct kombi kombi_obj, *ptr;
ptr = &kombi_obj;
printf("bitte Bezeichnung eingeben:");
fgets(kombi_obj.bezeichnung,sizeof(kombi_obj.bezei chnung),stdin);
printf("bitte zet eingeben:");
scanf("%lf",&kombi_obj.zet);
fflush(stdin);
printf("bitte atyp eingeben:");
kombi_obj.atyp=getchar();
show(ptr);
return 0;
}
it compiles just fine without any warnings or errors.
as you can see it should ask the user to enter 3 values.
the problem is that it will ask the first 2 values and just skip the third one.
the output looks like this:
bitte Bezeichnung eingeben:bla
bitte zet eingeben:123
bitte atyp eingeben:Bezeichnung: bla
Zet: 123.000000
Atyp:
i send the code to a friend using M$ visual studio and it just ran fine.
on the other hand i did send it to a friend using debian and it made the same as on my ubuntu.
could someone please point to me where the error is?
greetings and thanks for your advice
Bartuk
So i have a problem with a program i've written in C and compiled it using the standart gcc(gcc-Version 4.3.3 (Ubuntu 4.3.3-5ubuntu4))
actually i dont know if its a gcc bug or only my crappy coding skills.
so heres the complete code:
#include <stdio.h>
struct kombi
{
char bezeichnung[20];
double zet;
char atyp;
};
void show(struct kombi *kombi_ptr){
printf("Bezeichnung: %s\n",(kombi_ptr)->bezeichnung);
printf("Zet: %f\n",(kombi_ptr)->zet);
printf("Atyp: %c\n",(kombi_ptr)->atyp);
}
int main (void)
{
struct kombi kombi_obj, *ptr;
ptr = &kombi_obj;
printf("bitte Bezeichnung eingeben:");
fgets(kombi_obj.bezeichnung,sizeof(kombi_obj.bezei chnung),stdin);
printf("bitte zet eingeben:");
scanf("%lf",&kombi_obj.zet);
fflush(stdin);
printf("bitte atyp eingeben:");
kombi_obj.atyp=getchar();
show(ptr);
return 0;
}
it compiles just fine without any warnings or errors.
as you can see it should ask the user to enter 3 values.
the problem is that it will ask the first 2 values and just skip the third one.
the output looks like this:
bitte Bezeichnung eingeben:bla
bitte zet eingeben:123
bitte atyp eingeben:Bezeichnung: bla
Zet: 123.000000
Atyp:
i send the code to a friend using M$ visual studio and it just ran fine.
on the other hand i did send it to a friend using debian and it made the same as on my ubuntu.
could someone please point to me where the error is?
greetings and thanks for your advice
Bartuk