Scanning string arrays from file

This is a discussion on Scanning string arrays from file within the C Programming forums, part of the General Programming Boards category; Hey there, struggling learning this and first time poster here. Getting pretty aggravated trying to figure out a solution. Let's ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Angry Scanning string arrays from file

    Hey there, struggling learning this and first time poster here. Getting pretty aggravated trying to figure out a solution.

    Let's say you need to read in some data from a .dat file. The file will start by giving you an arbitrary integer "n"that determines the size of a vertical array or n by n matrix.

    For example, if your data file started out formatted like so:

    4
    labor;metals;plastics;elctrncs
    Charlie;Snoopy;Lucy;Linus

    BUT, the data file could also have several of these examples in the same data file one after each other where you would need to perform operations on them.

    How do I scan in the character strings of data into two single arrays of one name per row?

    Example, I want variable1 to be:
    labor
    metal
    plastics
    electncs

    and variable2 to be:
    charlie
    snoopy
    lucy
    linus

    When I try a while loop to fscanf to EOF, the %s into the array doesn't know when to stop inputting because it should be stopped based on the size of the first integer.
    When I try scanning in with a for loop and counter to play the strings into the storage cells based on i<(integer-1), I only get gibberish or it crashes.

    Any thoughts?

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    How many you pay to solve your homework?

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    It was just a simple syntax question on scanning a file. No worries, I got it figured out eventually. Guess this site is pretty worthless.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,578
    Quote Originally Posted by SimonBones View Post
    It was just a simple syntax question on scanning a file. No worries, I got it figured out eventually. Guess this site is pretty worthless.
    This site is for people able to read, understand, and follow the site directions.
    Note: This requires some work on the poster part; so, this site is useless to a lazy newbie programmer.

    http://cboard.cprogramming.com/c-pro...-homework.html

    Tim S.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by SimonBones View Post
    It was just a simple syntax question on scanning a file. No worries, I got it figured out eventually. Guess this site is pretty worthless.
    How can it possibly have been a syntax question.... you didn't post any code!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-29-2011, 01:02 PM
  2. Scanning Arrays from a file
    By Hikaru90 in forum C Programming
    Replies: 1
    Last Post: 02-10-2010, 08:06 PM
  3. scanning numbers in files into arrays
    By pepelepew in forum C Programming
    Replies: 3
    Last Post: 11-12-2009, 04:24 AM
  4. Searching and Scanning Arrays
    By apoc632 in forum C Programming
    Replies: 7
    Last Post: 11-28-2003, 02:28 PM
  5. scanning a string twice???
    By Lynux-Penguin in forum C Programming
    Replies: 7
    Last Post: 05-12-2002, 08:06 PM

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