Thread: scanf

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    scanf

    Can I change the scanf line in my program to a cout/cin line?
    What does scanf do anyways?

    here is the line:

    scanf("%d",&number);

    the program uses pass by pointer and function to accept a series of integers. The program terminates and displays the amount of times the number 20 is entered when a negative integer is entered.

    I have the code done already and it works..I just need the one scanf line simplified.....I don't want to use it because it is not used by my class text book and I don't want to loose points.

    Thanks.
    Jimmy

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    replace it with the following C++ equivalent

    where number is of type int.

    cin >> number;
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    10
    Thanks, that worked just as well.

    What is that scanf anyway and how is it different from the cin line?
    Jimmy

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    scanf() is one of the standard C functions used for input where cin is C++ standard way.

    the main difference in fact virtually the only difference is how they are and can be used.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM