POLALA.COM
welcome to my space
X
Welcome to:polala.com
Search:  
NAVIGATION - HOME

Storing data from a text file into an array

Published by: jack 2009-01-09
  • Persistent data (feb 99)::
    then to save the data pointed to by $data , open a text file and write the results One of the downside of Data::Dumper is that it cannot store coderefs ,
    http://www.stonehenge.com/merlyn/UnixReview/col24.html
    HOME
    Hello there, We are using a optimization tool called CPLEX and the inputs for this program is fed from a text file which contains a matrix with rows and colums (max rows and colums will be 100 X 100). I know how to call a C program into this optimization tool. I want to know how to store this data in array [i][j] from the text file, the delimiter used is comma ",". The text file say network.txt looks something like this. 1,0,0,1,0 0,1,1,0,1 0,0,0,1,0 1,1,0,1,0 I need this to be stored in array [i][j]. The program should strictly be in C only. Thanks. Perry p.s: Bonus will be given too
  • Reading a Delimited File using ASP.NET and VB.NET::
    Oct 5, 2003 Data is directly read from the delimited text file into arrays and manipulated. now we need a place to store the contents for the file.
    http://www.theukwebdesigncompany.com/articles/article.php?article=151
    HOME


  • Perry1872, This C program will do what you want. You can change the variable declaration to expand the matrix beyond 100 elements. You cn also change the filename from network.txt to whatever you need it to be. NOTE: You may need to unwrap lines wrapped by the answer box. // ------------- CODE BEGIN ------------- #include void main() { int n[100][100]; int i; int j; int a; int di; int dj; int quit; FILE *fp; char line[1024]; char *cp; i = 0; quit = 0; fp = fopen("network.txt", "r"); if(fp != NULL) { while((fgets(line, 1024, fp)) && (quit == 0)) { j = 0; cp = line; while((*cp != '') && (quit == 0)) { a = atoi(cp); if((i < 100) && (j < 100)) { n[i][j] = a; j++; while((*cp != ',') && (*cp != '')) cp++; if(*cp == ',') cp++; } else { quit = 1; fprintf(stderr, "Error: Rows or columns has exceeded 100. Exiting program.n"); } } i++; } fclose(fp); // DEBUG loop to print out array contents if(quit == 0) { for(di = 0; di < i; di++) { printf("ROW %d : ", di); for(dj = 0; dj < j; dj++) { printf("%d ", n[di][dj]); } printf("n"); } } } else { fprintf(stderr, "Error: Unable to open network.txt.n"); } } // ------------- CODE END ------------- Good luck with CPLEX! - Hammer Search strategy --------------- None. Wrote a C program per stated requirements.
  • Reading and writing text files with VB.NET - Program - Windows ::
    If i store data in text files in 3 different columns and i want to retreive . any one help me to store every line of the text file into an array and to
    http://www.builderau.com.au/program/windows/soa/Reading-and-writing-text-files-with-VB-NET/0,339024644,320267367,00.htm
    HOME



    Where's The Advantage In Windows Genuine Advantage?
    Stocks Bounce After S&P Joins Bear Market
    You are looking at:polala.com's Storing data from a text file into an array, click polala.com to home

    #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Storing data from a text file into an array , Please add it free.
    About us |Contact us |Advertisement |Site map |Exchange links
    Copyright© 2008polala.com All Rights Reserved