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

This is a discussion on help (read strings from file -> save each string's char in array) within the C Programming forums, part of the General Programming Boards category; can anyone suggest me a way of doing this? lets say we have a file input.in in the file we ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 04:16 AM

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