Thread: Formatting fprintf

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Formatting fprintf

    Hello,
    Let me first say I did search the forum as well as google and could not find exactly what I wanted to know.

    What I want to do is say I have the string "Hello World". How would I say use fprintf to just output "World", or even "ello Wor" to the file I am writing to?

    Also is there a way to compare parts of a string such as if I have two strings in an array like "Hello World" "Hello Earth" and I only wanted to fprintf the strings that ended with "Earth". Thank you.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You should look at the functions available in string.h (The C Standard Library - a good reference). You should use them to edit the string however you want, and then output the new string with fprintf.

    For instance, you could use strtok() to break it up into words.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    The problem I feel i'll run into with tokenizing is that I need to compare a list of last names and if the name is one I am looking for I need to print the first name and date of birth that go with it. The input file is separated by spaces so names such as "Van Wilder" will go into multiple tokens.

    The input file will look like:

    John Doe May 30 1977
    Chris Van Wilder June 07 2008

    THanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  3. fprintf to stderr crash programs
    By jlai in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2005, 08:51 AM
  4. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  5. fprintf
    By bennyandthejets in forum Windows Programming
    Replies: 10
    Last Post: 11-16-2002, 06:58 PM