Like Tree1Likes
  • 1 Post By Matticus

How to read a 2 line input

This is a discussion on How to read a 2 line input within the C Programming forums, part of the General Programming Boards category; I want to be able to read 2 line input, then safe them in separate arrays. soo; line1 input=array1 line2=array2 ...

  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
    2,542
    See strcpy or memcpy functions.

    strcpy - C++ Reference
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,268
    Call "fgets()" twice.
    stahta01 likes this.

  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
    2,268
    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
    2,268
    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
    289
    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, 09:51 AM
  4. Beginner Help Read Next Line of Input File
    By SkinnieMinnie in forum C++ Programming
    Replies: 10
    Last Post: 11-25-2007, 12: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21