Results 1 to 4 of 4

Thread: Heard about different forms of printf and scanf

  1. #1
    Contributing Member
    Join Date
    May 2006
    Answers
    72

    Heard about different forms of printf and scanf

    Hi,
    I have heard about print and scanf. But recently I cam across a term called sprintf. Could someone tell me what is this relate to? Is it same as printf. If not what is the difference. This would help us to program more efficiently using these options at appropriate places.

    Regards,
    Joel


  2. #2
    Contributing Member
    Join Date
    May 2006
    Answers
    85

    Re: Heard about different forms of printf and scanf

    Hi,
    printf is used to print output in standard output say display screen. In contrast sprintf is used to print something into a string instead of on the standard output.
    But there is one term called snprintf but I do not know about this. If someone could tell us the difference between these it would make this discussion more helpful.

    Regards,
    Norman


  3. #3
    Contributing Member
    Join Date
    May 2006
    Answers
    64

    Re: Heard about different forms of printf and scanf

    Hi,
    The piece of information that I know about sprint and snprintf is snprintf is more advantageous than sprintf. It would be nice if anyone could highlight the reasons on the same. Also we could have in this discussion about snscanf also. So someone put your thoughts and ideas in this.

    Regards,
    Janelyn


  4. #4
    Contributing Member
    Join Date
    May 2006
    Answers
    82

    Re: Heard about different forms of printf and scanf

    I do not have knowledge about snscanf but could let you know about snprint. snprintf is a function which has the syntax as below:
    int snprintf(char *s, size_t size, const char *format, ...)
    snprintf plays a very useful role by helping developers take care of buffer overflow. This is because by using snprint no more than size bytes is written into s. The return value from this function snprintf is an integer which indicates how much more space is required to write the string fully if it is not written fully. By making use of this value the users can have an idea to allocate storage space if they want to have the whole string written. Thus snprintf is used in managing the buffer in the above way. But one point to note is as sprintf comes along with ANSI C snprint is not widely used.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact