Thread: problem

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    99

    problem

    i writed the following program:
    #include <stdio.h>

    main()
    {
    int fn, fn2, sum;
    sum = fn + fn2;
    printf("Welcome to the addition machine!\n");
    printf("Write a number:");
    scanf("%i", fn);
    printf("Write second number:");
    scanf("%i", fn2);

    printf("The number is... %i\n", sum);


    }
    i don't get any problem in compiling but when running i see this

    Welcome to the addition machine!
    Write a number:12
    Write second number:12
    Segmentation fault
    what does segmentation fault means becasue i got that in some other programs i writed too!

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Take a look at this and see if this helps.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int fn, fn2, sum;
        sum = fn + fn2;
        printf("Welcome to the addition machine!\n");
        printf("Write a number: ");
        scanf("%i", &fn);
        printf("Write second number: ");
        scanf("%i", &fn2);
    
        sum = fn + fn2;
        printf("The number is... %i\n", sum);
    
        system("PAUSE");	
        return 0;
    }
    It is ALWAYS int main() not main().
    You should look up the address of operator '&'.
    Last edited by Bajanine; 12-04-2004 at 11:43 AM.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    Hey i solved the problem by adding & front of fn and fn2!
    i forget it again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM