Exforsys
+ Reply to Thread
Results 1 to 4 of 4

Best Alternative

This is a discussion on Best Alternative within the C and C++ forums, part of the Programming Talk category; I know one way of getting input from users is using scanf. But my friend told me that in real ...

  1. #1
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128

    Best Alternative

    I know one way of getting input from users is using scanf. But my friend told me that in real programming applications it is not good to sue scanf and it is always better to void scanf. Is this true and why is it so? If so what can be the best alternative for scanf


  2. #2
    caradoc is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    122
    cin is another way of getting input in C++ programming language. In C++ it is better to use scanf than cin. This is because cin takes much more time than scanf. The reason for this in cin it is necessary to specify the data type of input each time. But in scanf it is not so. It has format specifier which clearly depicts the data type used. So if there are larger say millions of records to be inputted to reduce time it is better to go for scanf than cin statement in C++. The same reason holds for cout and with printf concept also in C++.


  3. #3
    Sandhya.Kishannag is offline Member Array
    Join Date
    Feb 2012
    Answers
    66
    The scanf function reads input from the standard input stream stdin.If the string that is being accepted is longer than the buffer size, the characters will overflow into the adjoining memory space and hence scanf function is vulnerable to buffer overflow.The alternative can be fscanf which reads input from the stream pointer stream, and sscanf reads its input from the character string pointed to by str and fgets().


  4. #4
    arigatou is offline Junior Member Array
    Join Date
    Mar 2012
    Answers
    1
    Character will overflow into the adjacent memory space, so the scanf function is vulnerable to buffer overflow.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...