C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 31st, 2012, 04:51 AM
Mosdn85 Mosdn85 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Mosdn85 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 48 sec
Reputation 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

Reply With Quote
  #2  
Old December 31st, 2012, 05:00 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,130 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 19 h 43 m 21 sec
Reputation Power: 1949
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?

Reply With Quote
  #3  
Old December 31st, 2012, 06:01 AM
Mosdn85 Mosdn85 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Mosdn85 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 48 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #4  
Old December 31st, 2012, 06:05 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,130 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 19 h 43 m 21 sec
Reputation Power: 1949
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.

Reply With Quote
  #5  
Old December 31st, 2012, 09:07 AM
Mosdn85 Mosdn85 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Mosdn85 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 48 sec
Reputation Power: 0
Can't you give me the correct code?

You can do that in 5 sec! :-)

Reply With Quote
  #6  
Old December 31st, 2012, 06:12 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,130 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 19 h 43 m 21 sec
Reputation Power: 1949
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Output (created file) is empty...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap