#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Output (created file) is empty...


    I have a little problem,
    I can get any data in the created file:
    Code:
    ===================================

    #include <stdio.h>
    char candydata [999];
    int findAmountOfCandyCollected( int candyCollected, int candyLost , int candyate);
    int main(void)
    {
    int candyCollected;
    int candyLost;
    int candyate;

    printf( "Please input the amount of candycollected : " );
    scanf( "%d", &candyCollected );
    printf( "Please input the amount of candylost : " );
    scanf( "%d", &candyLost );
    printf( "Please input the amount of candyate : " );
    scanf( "%d", &candyate );
    printf( "The product of your three numbers is %d\n", findAmountOfCandyCollected( candyCollected, candyLost, candyate ) );
    getchar();
    }
    int findAmountOfCandyCollected (int candyCollected, int candyLost, int candyate)
    {
    return candyCollected - candyLost - candyate ;
    {
    int findAmountOfCandyCollected;

    FILE *dataptr;
    dataptr= fopen("candydata", "w");

    if (dataptr !=0)
    {
    fprintf(dataptr, "%d ", findAmountOfCandyCollected);


    }
    else

    {
    printf("could not open the file. /n)");
    }



    fclose(dataptr);
    return 0;
    }
    }

    What's wrong
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    The problem is that your program is nonsense:

    Code:
    #include <stdio.h>
    
    char candydata [999];
    int findAmountOfCandyCollected( int candyCollected, int candyLost , int candyate);
    
    int main(void)
    { 
        int candyCollected;
        int candyLost;
        int candyate;
    
        printf( "Please input the amount of candycollected : " );
        scanf( "%d", &candyCollected );
        printf( "Please input the amount of candylost : " );
        scanf( "%d", &candyLost );
        printf( "Please input the amount of candyate : " );
        scanf( "%d", &candyate );
        printf( "The product of your three numbers is %d\n", findAmountOfCandyCollected( candyCollected, candyLost, candyate ) );
        getchar();
    }
    
    int findAmountOfCandyCollected (int candyCollected, int candyLost, int candyate)
    {
        return candyCollected - candyLost - candyate ;
        {
            int findAmountOfCandyCollected;
    
            FILE *dataptr;
            dataptr= fopen("candydata", "w");
    
            if (dataptr !=0)
            {
                fprintf(dataptr, "%d ", findAmountOfCandyCollected);
            }
            else
    
            {
                printf("could not open the file. /n)");
            }
            fclose(dataptr);
            return 0;
        }
    }
    Your main function promised to return an int, whereas it returned absolutely nothing.

    Your findAmountOfCandyCollected immediately performed a return, which means that everything after that was completely ignored.

    Just what the frak do you think you are trying to accomplish there?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by dwise1_aol
    The problem is that your program is nonsense:

    Code:
    #include <stdio.h>
    
    char candydata [999];
    int findAmountOfCandyCollected( int candyCollected, int candyLost , int candyate);
    
    int main(void)
    { 
        int candyCollected;
        int candyLost;
        int candyate;
    
        printf( "Please input the amount of candycollected : " );
        scanf( "%d", &candyCollected );
        printf( "Please input the amount of candylost : " );
        scanf( "%d", &candyLost );
        printf( "Please input the amount of candyate : " );
        scanf( "%d", &candyate );
        printf( "The product of your three numbers is %d\n", findAmountOfCandyCollected( candyCollected, candyLost, candyate ) );
        getchar();
    }
    
    int findAmountOfCandyCollected (int candyCollected, int candyLost, int candyate)
    {
        return candyCollected - candyLost - candyate ;
        {
            int findAmountOfCandyCollected;
    
            FILE *dataptr;
            dataptr= fopen("candydata", "w");
    
            if (dataptr !=0)
            {
                fprintf(dataptr, "%d ", findAmountOfCandyCollected);
            }
            else
    
            {
                printf("could not open the file. /n)");
            }
            fclose(dataptr);
            return 0;
        }
    }
    Your main function promised to return an int, whereas it returned absolutely nothing.

    Your findAmountOfCandyCollected immediately performed a return, which means that everything after that was completely ignored.

    Just what the frak do you think you are trying to accomplish there?


    I'm a starter :) Just a few days ago :)

    i just want in the created fill the sum of candyCollected, int candyLost, int candyate
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Then find a way to run the code after the return statement in the findAmountOfCandyCollected function.

    Once you execute a return statement, you have left that function.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Can't you give me the correct code?

    You can do that in 5 sec! :-)
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Think about it for a moment. You want to run the rest of the code in that function, but you can't because the first line of code is a return statement. Why don't you remove the return statement?

IMN logo majestic logo threadwatch logo seochat tools logo