Thread: How to read a 2 line input

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    35

    How to read a 2 line input

    I want to be able to read 2 line input, then safe them in separate arrays.

    soo;

    line1 input=array1
    line2=array2

    Thank youu

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    See strcpy or memcpy functions.

    strcpy - C++ Reference
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Call "fgets()" twice.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    I dont really understand, if i have this at the standard input
    12345
    67890
    how would i get the program to read that? :s

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Are you expecting numbers or strings?

    Do you know how to read input and store it in a variable?

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    its eventually going to be for a poker hand evaluator. a,k,q,j,0,9,8,7,6,5,4,3,2 and d,s,h,c

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You can either read in each line character-by-character, or you can read each line as a complete string. In either case, each line can be stored in its own array.

    Here's a link to the tutorial on strings from this site:

    C Strings - Cprogramming.com

    Note the usage of "fgets()" to read a string from a line.

    Start small - write a program to read a string or two and print them out to the screen. When that is working well, and you're more comfortable with strings, add some more code to analyze the strings for content.

  8. #8
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    You're going to need to post some code first. Then ask some specific question about the code posted. Here's a link to a relevant post and response; look at the response from Whiteflags when you click the link.

    please help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 08-07-2011, 09:55 PM
  2. Replies: 2
    Last Post: 03-31-2011, 04:50 PM
  3. Read text file line by line and write lines to other files
    By magische_vogel in forum C Programming
    Replies: 10
    Last Post: 01-23-2011, 10:51 AM
  4. Beginner Help Read Next Line of Input File
    By SkinnieMinnie in forum C++ Programming
    Replies: 10
    Last Post: 11-25-2007, 01:23 AM
  5. How can I read until the end of an input line?
    By Bad_Scooter in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2003, 09:29 PM

Tags for this Thread