I'm an extremely fast learner and never need to study, so I won't be hard to teach.
As you might already know, I'm 99% self-taught in BASIC and am extremely proficient with it, so I don't think I should have a difficult time once I get through the basics.

I'd learn about this at school, that is, if my school offered such a course, at ALL. ;-;
Hmm, have you tried online tutorials and perhaps books on the subject at your local library/bookstore? I know that those really helped me get a start at learning <insert various languages here>
qazz42 wrote:
Hmm, have you tried online tutorials and perhaps books on the subject at your local library/bookstore? I know that those really helped me get a start at learning <insert various languages here>

I'd rather have someone to talk to, it's more helpful. x:
You should start with a tutorial or book, and then if you have any questions hop on here and ask.
I'd be glad to help! I do recommend trying to go through cprogramming.com's excellent set of tutorials, but once you at least attempt to get as far as you can with that, I'd be more than happy to help you along.
Ashbad wrote:
I'd be glad to help! I do recommend trying to go through cprogramming.com's excellent set of tutorials, but once you at least attempt to get as far as you can with that, I'd be more than happy to help you along.


Okay, I'll try that soon, and then I'll get back to you.



Okay, so I'm going through the basics, so far I've gotten through if and else statements, but I have a problem..

After the first scanf, the program no longer waits for input at getchar();
Hmm....


Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,x,y,z;
    printf("Babeh's first C program\n");
    getchar();
    printf("How many times did you cuddle last night?\n");
    scanf("%d",&a);
    printf("Orly? You cuddled %d times last night?\n",a);
    a=a+3;
    printf("Because I think you actually did it %d times...\n",a);
    getchar();
    printf("Would you lie to me? Q~Q\n");
    printf("1=Yes 2=No\n");
    scanf("%d",&b);
    if (b==2){
    printf("Oh, thank goodness...\n");
    printf("You had me worried...\n");
    getchar();
    printf("I was actually considering not giving you a hug! D:\n");
    }
    if (b==1){
    printf("I... I thought we had something SPECIAL!!\n");
    printf("HOW COULD YOU?!\n");
    getchar();
    printf("WE'RE NOT BESTIES FOR LIFE FRIENDS FOREVER LEAVE EACHOTHER NEVER EVER BUTT BUDDIES ANYMORE Q~Q\n");
    }
    return 0;
}


Note, this is my first program in C and it was born half an hour ago qq
why not use getchar() to check for a certain character to pressed? getchar() literally just takes the next char in the stdin stream, and returns it. You could use the letter 'n' to denote the next "function" in the program, and do so by using:


Code:
while(getchar()!='n');


which will wait in an infinite loop until the letter 'n' is pressed.
Ashbad wrote:
why not use getchar() to check for a certain character to pressed? getchar() literally just takes the next char in the stdin stream, and returns it. You could use the letter 'n' to denote the next "function" in the program, and do so by using:


Code:
while(getchar()!='n');


which will wait in an infinite loop until the letter 'n' is pressed.


I don't understand.
So, the problem with the putchar's is coming from the scanf. It reads numbers up until an endline ('\n'). Since the endline isn't what it is looking for, it leaves it in stdin. If you print out what the getchar() reads, it is 10, or '\n'. The solution: drain stdin.
Code:
#include <stdio.h>

int drain()
{
  int ch = 0;
  while((ch = getc(stdin)) != EOF && ch != '\n');
  return EOF == ch;
}

int main()
{
    int a;
    printf("Babeh's first C program\n");
    getchar();
    printf("How many times did you cuddle last night?\n");
    scanf("%d",&a);
    printf("Orly? You cuddled %d times last night?\n",a);
    a=a+3;
    printf("Because I think you actually did it %d times...\n",a);
    drain();
    getchar();
    printf("Would you lie to me? Q~Q\n");
    printf("1=Yes 2=No\n");
    scanf("%d",&a);
    if (a==2){
    printf("Oh, thank goodness...\n");
    printf("You had me worried...\n");
    drain();
    getchar();
    printf("I was actually considering not giving you a hug! D:\n");
    }
    else if (a==1){
    printf("I... I thought we had something SPECIAL!!\n");
    printf("HOW COULD YOU?!\n");
    drain();
    getchar();
    printf("WE'RE NOT BESTIES FOR LIFE FRIENDS FOREVER LEAVE EACHOTHER NEVER EVER BUTT BUDDIES ANYMORE Q~Q\n");
    }
    return 0;
}
Take a look at Kernighan and Ritchie's book on ANSI C. It's got all you really need to know. Google around for a PDF or pick it up at a library. The only things that are really missing are the (minute amount of) features in C99. My friend is also struggling with C at the moment; he's trying his best to document his struggles through learning C. He is working on backed up school assignments though, so he might not update for a while.
http://darkwoods.tk/
I absolutely recommend K&R, so Kaslai++ for that. I didn't really find myself struggling with C too much, but I also had BASIC and PHP under my belt when I learned C, so I already knew a lot of the structural ideas.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement