Thread: help (read strings from file -> save each string's char in array)

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    5

    help (read strings from file -> save each string's char in array)

    can anyone suggest me a way of doing this?

    lets say we have a file input.in
    in the file we have two words each has from 1 to 10 chars

    for example

    input.in

    quote
    blues

    what we want to do is code an app that reads the words from the file and saves the first word's chars in an array called a[] and the second word's chars in an array called b[].

    I have some solution on this, but its crappy, i would show you if i was at home now, so

    thanks in advance.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    use fgets twice

    (do not forget to check the return value)

    use strchr to locate teh \n character and remove it from the string like in the sample http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  2. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  3. File > Array
    By mau108 in forum C Programming
    Replies: 2
    Last Post: 04-26-2005, 10:49 PM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. read from .txt file & put into array?
    By slow brain in forum C Programming
    Replies: 6
    Last Post: 02-25-2003, 05:16 AM