Read Text File into an Array

This is a discussion on Read Text File into an Array within the C Programming forums, part of the General Programming Boards category; Hi, I need to use the qsort to sort the content of an unknown text file size by reading it ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    13

    Unhappy Read Text File into an Array

    Hi, I need to use the qsort to sort the content of an unknown text file size by reading it into an array and then sort the lines. I know C language well, could someone help? I can get the file size and dynamically allocate memory, but how would I treat the allocated memory like an array like having lines of text file?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Use a for loop,

    Code:
    for(i = 0; i < rows; i++)
       fscanf("%s", &stringArray[i]); //don't reference the second dimension here
    I haven't run this, but it looks ok.

    You will have to show your code for further help. That's the forum policy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in an array of text from a file?
    By suzakugaiden in forum C++ Programming
    Replies: 6
    Last Post: 01-04-2006, 03:17 PM
  2. Read text from a file into an array
    By ccwash in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2005, 04:19 PM
  3. read from .txt file & put into array?
    By slow brain in forum C Programming
    Replies: 6
    Last Post: 02-25-2003, 05:16 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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