fprintf problem

This is a discussion on fprintf problem within the C Programming forums, part of the General Programming Boards category; Hi, I have a problem with fprintf(File *arg1, char * arg2) for I wanted to print an integer or a ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    1

    fprintf problem

    Hi, I have a problem with fprintf(File *arg1, char * arg2) for I wanted to print an integer or a double variable onto a file. As far as I know, the fprintf command can only allow a string, or a character pointer in argument 2. Can somebody help me in telling me what to do or where to look for in allowing fprintf to accept integer/double variables or possibly ways to convert integer or a double into a char*?

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    The second argument to fprintf is a format string, so it works nearly identically to printf.

    Therefore :

    For doubles :

    Code:
    fprintf(file_pointer_name, "%f", double_value);
    For intergers :

    Code:
    fprintf(file_pointer_name,"%d", integer_value);
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  2. Problems writing some chars to files with fprintf
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 04-18-2006, 07:00 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21