Thread: New to C..and programming

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    2

    New to C..and programming

    Hey everyone, I've just started programming and decided to start with C. I have written this program but it will not run and I was wondering if anyone could help me? Your help would be greatly appreciated.


    1. #include (stdio.h)

    2. void Main (void) {
    3. char c;

    4. printf("Enter a sentence:\n");

    5. scanf("%c", &c);
    6. while (c != ".") {
    7. printf("%c\n", c);
    8. scanf("%c", &c);
    9. }

    10. printf(".\n");
    11. }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    First of all, you should use [code] tags around your code.

    1. Main should be main (make the 'm' lower case).
    2. main() returns int, not void.
    3. Should be <stdio.h>, not (stdio.h)
    4. To compare against a character, use single quotes -- not double (See the period in your while loop).

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    2
    Thank you so much,you've helped so much!

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    And of course, if you are actually compiling with those line numbers in the code, remove them.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    And since you're a beginner, allow me to add some more information you might like to know, corresponding to bithub's numbers:

    1) C is case sensitive, so you can have add, ADD, and Add as all different functions. Your program could have all 3, it just wouldn't be very readable.

    2) The C standard says that main returns an int. Return 0 if everything is fine, return other numbers as you please to indicate errors. By default, main will return 0 for you (I think...). The OS uses this - some people don't do it and say "void main works for me" but it's against the standard. (Although I believe some microcontrollers require no return value).

    3) Standard header files go in < >'s. When you make your own header files they go in " ";s

    4) A single character is single quotes. Using double quotes makes the compiler think it's a whole string, and will return a pointer to the beginning of that string.

    Also - when you post problems, also post the specific error message and/or problem.

Popular pages Recent additions subscribe to a feed