Like Tree1Likes
  • 1 Post By c99tutorial

simple first attempt on method

This is a discussion on simple first attempt on method within the C Programming forums, part of the General Programming Boards category; this is my first attempt on methods and im new for c programming.im using the Cygwin compiler and here's what ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    2

    simple first attempt on method

    this is my first attempt on methods and im new for c programming.im using the Cygwin compiler and here's what i did

    Code:
    # include <stdio.h>
    
    
    int add(int x,int y)
    {
        int result =x+y;
        return result;
    
    
    }
    
    
    int main()
    {
    
    
        int sum=add(5,12);
        printf("The addition of 5 and 12 is %d.\n", sum);
        //printf(sum);
        return 0;
    }
    I used netbeans 7.2 and compiled it using cygwin and im getting an error.any idea will be really helpful the file i saved is add.c

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, but please - copy the error into your posts about an error. We can't read it, no matter how much we ask Santa for help with it.

    Congrats on using code tags on your first post, btw!

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Try removing the space after the # here
    Code:
    # include <stdio.h>

  4. #4
    Registered User
    Join Date
    Dec 2012
    Posts
    2
    Quote Originally Posted by Adak View Post
    Welcome to the forum, but please - copy the error into your posts about an error. We can't read it, no matter how much we ask Santa for help with it.

    Congrats on using code tags on your first post, btw!

    This is what i got as the error message
    Code:
    CLEAN SUCCESSFUL (total time: 101ms)
    
    
    mkdir -p build/Debug/Cygwin-Windows
    rm -f build/Debug/Cygwin-Windows/add.o.d
    gcc.exe    -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/add.o.d -o build/Debug/Cygwin-Windows/add.o add.c
    add.c: In function `main':
    add.c:22: warning: passing arg 1 of `printf' makes pointer from integer without a cast
    add.c:27:2: warning: no newline at end of file
    
    
    
    
    BUILD SUCCESSFUL (total time: 151ms)

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    1,053
    Quote Originally Posted by chawb View Post
    This is what i got as the error message
    Code:
    add.c: In function `main':
    add.c:22: warning: passing arg 1 of `printf' makes pointer from integer without a cast
    add.c:27:2: warning: no newline at end of file
    You'll have to go to line 22 in your file to see what happened. The line you commented out in your first post might have caused this message

    printf(sum);

    The correction would be

    printf("%d", sum):

    The first argument of printf should always be a format string. If it isn't, it could be implicitly cast to a string (i.e. a pointer) and would give the warning that you saw.

    The warning about no newline at end of file can be fixed by going to the end of your source file and pressing return.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Simple method terrible implementation
    By DrowningInCode in forum C Programming
    Replies: 8
    Last Post: 04-26-2010, 04:49 AM
  3. Replies: 5
    Last Post: 01-02-2008, 05:53 AM
  4. attempt 2
    By cppdungeon in forum C++ Programming
    Replies: 3
    Last Post: 05-27-2005, 07:57 PM
  5. Simple method of coloured text?
    By SPiRiToFCaT in forum C++ Programming
    Replies: 3
    Last Post: 09-04-2002, 09:46 PM

Tags for this Thread


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