#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    C programming Question Help1


    Write a simplified version of printf in which the two conversion specifications are %d and %s. Each %d in the the format string indicates an int argument and each %s indicates a char* (string) argument. If the function encounters a % character thatís not immediately followed by a d or s character, it should ignore both characters. The function should use calls of putchar to produce all output. You may assume that the format string doesnít contain escape sequences. Test your function with a C program
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    For extra credit, when given the source your routine should verify the arguments passed match the format string. Yes, printf is variadic. Your version should be so as well.

    Post again if you run into specific trouble with your algorithm or program. It's best if you post

    )A minimal amount of code that exhibits the problem;
    )Input that caused the trouble if you make it as far as runtime;
    )Output;
    )Output you expected. That's critical. Would you believe that many of the posts here don't include "why it's a problem" information? In this case the problem appears well defined. Good start.
    Last edited by b49P23TIvg; April 6th, 2013 at 07:09 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Originally Posted by UnknownK
    Write a simplified version of printf in which the two conversion specifications are %d and %s. Each %d in the the format string indicates an int argument and each %s indicates a char* (string) argument. If the function encounters a % character thatís not immediately followed by a d or s character, it should ignore both characters. The function should use calls of putchar to produce all output. You may assume that the format string doesnít contain escape sequences. Test your function with a C program
    Pretty sure nobody here is going to do your homework for you. At least that's the way it should be. Have you got a specific question to ask?

    Why don't you get started by writing a function that finds all of the '%" symbols in a string passed in as a parameter and outputs the index of that symbol and the value of the following symbol? That might be a good starting point.
    I no longer wish to be associated with this site.

IMN logo majestic logo threadwatch logo seochat tools logo