PDA

View Full Version : Is this my fault, or the compilers fault?


yamoo
08-18-2005, 03:59 PM
On this code:
#include <stdio.h>

int
main(void)
{
char letter_1, letter_2, letter_3;
int year;

printf("Enter a three letter name and press enter> \n");
scanf("%c%c%c", &letter_1, &letter_2, &letter_3);
printf("please enter the year \n");
scanf("%d", &year);
printf("Hi, %c%c%c. %d is is a great year to study \n");
system("PAUSE");

return 0;
}


I run it, enter a three letter name, such as bob, with the year, such as 2005, and it returns this:
Hi pvu. 2009315348 is is a great year to study.

Why doesn't it return the year or name I entered?


I'm using Bloodshed 4.9.9.2 beta.

So, who's fault is it? Mine or the compiler? (I just started C yesterday, so I don't know...)


I included the exe file in the zip below.
So you can run it on your own machine.

aman
08-18-2005, 04:44 PM
heh yea this is good stuff :)

You are printing garbage. Try adding the needed parameters to the printf() function.

printf("Hi, %c%c%c. %d is is a great year to study \n", letter_1, letter_2, letter_3, year);

aman
08-18-2005, 04:48 PM
Oh and BTW, the answer to your question is.. It is ALWAYS your fault. :p

SpirtOfGrandeur
08-18-2005, 04:53 PM
Oh and BTW, the answer to your question is.. It is ALWAYS your fault. :p


Ehehe unless you are that .00001% that are using some thing that is so obsecure and the compiler has not been tested well enough for that then yes it is your fault... And i definatly do not think a basic program is going to break a compiler...

yamoo
08-18-2005, 05:09 PM
heh yea this is good stuff :)

You are printing garbage. Try adding the needed parameters to the printf() function.

printf("Hi, %c%c%c. %d is is a great year to study \n", letter_1, letter_2, letter_3, year);
Thanks aman :)