Thread: Help with scanf (I'm a beginner)

  1. #1
    Registered User
    Join Date
    Mar 2015
    Location
    Campinas, Brazil
    Posts
    2

    Help with scanf (I'm a beginner)

    Hey guys, I'm having some troubles making a program my teacher asked me this week. The algorithm is fine to do, but the entries are screwing me up.

    Well, I think it is kinda simple to solve it but still, I'm a beginner and don't know much yet.

    First of all, the program will read 3 int values, one of then we will call N (The others aren't important for this doubt).

    Then it will read N values, all in the same line.

    For example:

    First entry: x y 10
    Second entry: a b c d e f g h j i

    First entry: x y 3
    Second entry: a b c

    First entry: x y 7
    Second entry: a b c d e f g

    I don't know how to do that. Can't use switch (N) and case 1 <= x <= N, because N is a number between 1 and 20 and the code would be really long, and I don't think it should since my class are all beginner at programming.

    Any suggestions? Thanks!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Are you actually going to be entering letters? Or are those just place-holders for integers?

    I don't know how to do that. Can't use switch (N) and case 1 <= x <= N, because N is a number between 1 and 20 and the code would be really long, and I don't think it should since my class are all beginner at programming.
    Assuming there are only integer inputs ... have you learned about anything yet that allows a section of code to repeat? Perhaps with criteria that, when met, will cause that code to stop repeating?

  3. #3
    Registered User
    Join Date
    Mar 2015
    Location
    Campinas, Brazil
    Posts
    2
    Quote Originally Posted by Matticus View Post
    Are you actually going to be entering letters? Or are those just place-holders for integers?



    Assuming there are only integer inputs ... have you learned about anything yet that allows a section of code to repeat? Perhaps with criteria that, when met, will cause that code to stop repeating?
    1. Those are just place-holders for integers.

    2. I've already learned about while/do while/for, but I don't know how can I use it here. I mean, if I only enter with one scanf inside a for structure, will it read all entries even if they are on the same line?

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Why don't you try out a little sample program to see for yourself if it will or won't work?

    And it's a "for()" loop - a structure is something else entirely (terminology is important).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner scanf
    By mutleymatt in forum C Programming
    Replies: 1
    Last Post: 06-11-2012, 12:41 PM
  2. Beginner and scanf
    By Chleborad in forum C Programming
    Replies: 12
    Last Post: 02-17-2011, 01:11 AM
  3. Beginner question about scanf/printf
    By mickeyd in forum C Programming
    Replies: 6
    Last Post: 04-17-2010, 09:39 PM
  4. Simple Scanf question for beginner
    By somekid413 in forum C Programming
    Replies: 1
    Last Post: 12-15-2009, 04:56 PM
  5. Beginner question-scanf being weird
    By pernjuke in forum C Programming
    Replies: 5
    Last Post: 11-22-2006, 09:18 AM