Embarassing Noob question

This is a discussion on Embarassing Noob question within the C Programming forums, part of the General Programming Boards category; I'm pretty much brand new to C and am working my way through chapter 2 of "Teach Yourself C in ...

  1. #1
    RVC
    RVC is offline
    Registered User
    Join Date
    Mar 2011
    Location
    Central Florida
    Posts
    8

    Embarassing Noob question

    I'm pretty much brand new to C and am working my way through chapter 2 of "Teach Yourself C in 21 Days" at:

    Teach Yourself C in 21 Days -- Table of Contents

    I'm using Pelles C. I've typed the first program in and came up with the expected string of warnings and errors when I tried to compile it. The code and messages are below. The first error is "c(8): warning #2099: Missing type specifier; assuming 'int'." I can find nothing wrong with line or with any of the rest of the code. I even tried pasting in the code with the same results with the same list of warnings and errors.

    Apparently there is something going on that I am not aware of. A shove in the right direction would be appreciated.

    Thank you.

    RVC

    ----------------------------------------------------------

    Following is the code.

    Code:
    /* Program to calculate the product of two numbers */
    #include <stdio.h>
    
    int a, b, c;
    
    int product (int x, int y);
    
    main ()
    {
    	/* input first number */
    	printf("Enter a number between 1 and 100:" );
    	scanf("%d", &a);
    	
    	/* Input the second number */
    	printf("Enter another number between 1 and 100: ");
    	scanf("%d", %b);
    
    	/* Calculate and display the product */
    	c = product (a, b);
    	printf ("%d times %d = %d\n", a, b, c);
    
    	return 0;
    }
    
    /*Function returns the product of its two argguments */
    int product (int x, int y)
    {
    	return (x * y);
    }
    ---------------------------------------------

    Following are the warning and error messages

    Building Multiply.obj.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(8): warning #2099: Missing type specifier; assuming 'int'.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): error #2039: Illegal expression.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): error #2001: Syntax error: expected ')' but found 'b'.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): warning #2234: Argument 2 to 'scanf' does not match the format string; expected 'int *' but found 'int'.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): error #2001: Syntax error: expected ';' but found 'b'.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): error #2001: Syntax error: expected ';' but found ')'.
    C:\Documents and Settings\Rick Van Clief\My Documents\C programs\Multiply.c(16): error #2061: Illegal statement termination.
    *** Error code: 1 ***
    Done.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    The first message is a warning, not error. You should not rely on this compiler assumption and write:
    Code:
    int main()
    instead of
    Code:
    main()
    Code:
    printf("Enter another number between 1 and 100: ");
    scanf("%d", %b);
    You missed reference operator with modulo:
    Code:
    printf("Enter another number between 1 and 100: ");
    scanf("%d", &b);
    I never put signature, but I decided to make an exception.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    The cause of your first warning:
    Code:
    main ()
    That should be:
    Code:
    int main(void)
    The cause of your second error:
    Code:
    scanf("%d", %b);
    Should be:
    Code:
    scanf("%d", &b);
    EDIT: Not fast enough
    If you understand what you're doing, you're not learning anything.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by RVC View Post
    I'm pretty much brand new to C and am working my way through chapter 2 of "Teach Yourself C in 21 Days" at:

    Apparently there is something going on that I am not aware of. A shove in the right direction would be appreciated.
    Yes...there is something going on.... Teach Yourself C in 21 days predates the current C99 standard that PellesC adheres to. If you look at the PellesC help file you will find the correct entry points are defined in the appendix.

    In fact PellesC has one of the best help files I've seen. (hint: Put the cursor on any keyword and press F1)

    In PellesC the entry point is C99 standard ... either
    Code:
    int main (void)
    or
    Code:
    int main (int argc, char * argv[])
    and main always has to return a value (usually 0 or an errorlevel)
    Code:
    return 0;
    The other error is about using % (modulous) instead of & (address of) in your scanf() statements.
    Last edited by CommonTater; 03-11-2011 at 12:26 PM.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    And in 21 days he will understand the importance of that link...

    Six years into it --more than half way there-- and still getting surprised everyday.

  7. #7
    RVC
    RVC is offline
    Registered User
    Join Date
    Mar 2011
    Location
    Central Florida
    Posts
    8
    I appreciate the help. Implementing your suggestions solved the issue.

    Thanks also for the link to "Teach Yourself Programming in 10 years" - a really great read. At 62 I am considerably past the point of expecting anything worthwhile to come quickly or even in 21 days. I selected the on-line resource mentioned because it seemed to offer an orderly progression that would give me a decent introduction to C and because it was free.

    Unfortunately as there is evidently an incompatibility between "Teach Yourself C in 21 Days" and PellesC I will need to find some other resource. Such is life on the learning curve.

    In any event, thanks again for your input.

    RVC

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by RVC View Post
    I appreciate the help. Implementing your suggestions solved the issue.

    Thanks also for the link to "Teach Yourself Programming in 10 years" - a really great read. At 62 I am considerably past the point of expecting anything worthwhile to come quickly or even in 21 days. I selected the on-line resource mentioned because it seemed to offer an orderly progression that would give me a decent introduction to C and because it was free.

    Unfortunately as there is evidently an incompatibility between "Teach Yourself C in 21 Days" and PellesC I will need to find some other resource. Such is life on the learning curve.

    In any event, thanks again for your input.

    RVC
    Stay the course my friend... The incompatibilities are truly minor, mostly that int main (void) thing and perhaps half a dozen library functions. A big part of a prgrammer's skill is to be able to adapt to these situations. Running away is not the answer. Use the PellesC help files, everything in the standard C99 library and Pelle's extension libraries is fully documented... There should be no problem you can't solve.

    FWIW... I started with 21 days and Pelles... and I was 54 at the time...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob question about RAM
    By crvenkapa in forum Tech Board
    Replies: 2
    Last Post: 03-26-2010, 04:41 PM
  2. Noob Question: Can't compile with "end1"
    By Lillers in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2010, 04:23 AM
  3. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 09:28 PM
  4. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 01:28 PM
  5. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21