My first C program [Help]
Posted: Wed Dec 30, 2009 9:01 pm
First off, let me say that I am only 12 years old.
With that being said, my brain power is no match to yours
I am learning C as my first programming language.
The book I am reading is "Absolute Beginners Guide to C".
I am working on my first real, interactive program.
Heres the source:
But when I type my 'yes or no' response, the program crashes!
Can anybody please explain this?
Edit: Please ignore the horrible whitespace used in my program, i think i am messing up spacing in some parts.
Thanks, Dex.
With that being said, my brain power is no match to yours
I am learning C as my first programming language.
The book I am reading is "Absolute Beginners Guide to C".
I am working on my first real, interactive program.
Heres the source:
Code: Select all
/* Written by Dex*/
/* -Do you like my name?- Written in C++ */
#include <stdio.h>
main()
{
char name[4]; /* The variable that stores the yes/no choice */
printf("Hello, i'm Dex, do you like my name? [Say yes or no] \n"); /* Asking for you
to enter 'yes' or 'no' */
scanf("%c", name[4]); /* Character input for the 'name' variable */
if(name == "yes") /* If the user enters the word 'yes' */
{
printf("/n Really? Thanks, I like my name, too"); /* Happy message */
}
else
printf("/n What? You don't like my name? -Sadface-"); /* Sad message */
}
But when I type my 'yes or no' response, the program crashes!
Can anybody please explain this?
Edit: Please ignore the horrible whitespace used in my program, i think i am messing up spacing in some parts.
Thanks, Dex.