Can someone fix this? 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; } }
you didn't say what was wrong or what it should be doing, but your function is returning a value without ever entering the file operation. It looks like the function might be wanting something like below Code: int function(int a, int b, int c) { FILE *f; ... fprintf(f, "%d ", a - b - c); ... return a - b - c; } really it depends on what you're wanting to return and what you're actually trying to do.
Hi Mos, Wish you a happy new year. I did not see any error in your code, other than using getchar() at the end. You have to use getch() instead of getchar() - Hope this should solve your problem.. Thanks, Tulasi