Thread: fprintf will NOT WORK !!!

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    Angry fprintf will NOT WORK !!!

    Been hammering @ this for a few days now. The code works like a champ. I just need the results printed @ the specified loc(myOutput.txt). Unfortionaly this is giving me trouble, can someone help me a little and figure out where I went wrong:

    include <stdio.h>
    #include <conio.h>
    #include <math.h>

    void main(void)
    {
    char c;
    int N,x,iter = 1;

    FILE *outptr;
    outptr=fopen("myOutput.txt","wt");
    printf("\nPlease enter a value for N ");
    scanf("%i",&N);
    printf("\n ");
    for(x = N, iter = 0; x > 1; x--)
    {
    printf("%i", x);
    printf(" + ");
    iter = iter + x;
    fprintf(outptr, "%i", x);
    fprintf(outptr, " + ");
    }
    printf(" 1 = ");
    printf("%i", iter);
    getch();
    fclose(outptr);

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    outptr=fopen("myOutput.txt","wt");
    "wt" is not a valid mode. It's "w" for text mode, "wb" for binary.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    Nope still doesn't work... The myOutput.txt is created but thinging goes into it. I just don't get it, It doesn't make sense.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Don't use void main. If you're familar with the statements your coding with in this program, try reading the source code backwards. You usually catch the small errors better that way. If the file is created, but nothing is placed in it, look over your fprintf statements closely.
    The world is waiting. I must leave you now.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    Maybe try using a different output function. Try fputs(), considering you are not making use of the formatting capabilities of the printf() family.
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  6. #6
    Unregistered
    Guest
    Make sure there is a # in front of include <stdio.h>.
    Why not print to the screen and see if it works?

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    Okay, I replaced the fprints w/fputs still does not work. Also There was a #by include I just missed it when I coppied the source. Also What should I put instead of void main void; this is how I was taught.

    Any other ideas ?

    It justs doesn't make sense, and its starting to ........ me off :-)

  8. #8
    Unregistered
    Guest
    Maybe try adding stdlib.h.

  9. #9
    Unregistered
    Guest
    int main (void)

  10. #10
    Unregistered
    Guest
    I assume you have return(0) and the closing brace.
    You define a char c, but don't seem to use it?

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    nope

    Tried the int main (void) and the <stdlib.h>. I swaer if I don't fix this I am gonna throw my laptop throughmy window.

  12. #12
    Unregistered
    Guest
    The return(0) satisfies the int part of int main (void).
    Why the getch() at the end?

  13. #13
    Unregistered
    Guest
    If you're not in too big of a hurry, Prelude or one of the others could figure this out real quick in the morning.

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    I am not fimiliar w/ int main (void).... Getch(); lets the program stop at the end so you can see your code not flash by. I don't get however what you mean ? Are you seggesting that when using int main (void) to use return(0); instead of getch();.

    ?

  15. #15
    Unregistered
    Guest
    int main (void) is the standard way to write main.
    Since you specified that you are returning an int,
    you include return (0) at the end of main.
    I see now how you are using getch().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM