The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Output (created file) is empty...
Discuss Output (created file) is empty... in the C Programming forum on Dev Shed. Output (created file) is empty... C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 31st, 2012, 04:51 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
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
|

December 31st, 2012, 05:00 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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?
|

December 31st, 2012, 06:01 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
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
|

December 31st, 2012, 06:05 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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.
|

December 31st, 2012, 09:07 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
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! :-)
|

December 31st, 2012, 06:12 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|