Thread: problem to read large file.

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    problem to read large file.

    Hello,
    I have problem to read large file.
    The file have 900 000 lines, and 3 column:
    First to columns is coordinate - lat, lon
    third column is integer.
    When array is 600 000 program work, but if I put 700 000 don't work
    What I must to do?

    Code is:

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main(void)
    {
    
    	FILE *in;
    	float lat[600000], lon[600000];
    	int value[600000], i;
    
    
    	/*open file*/
    	if((in=fopen("file2.txt", "r")) == NULL) {
    		printf("Cannot open file");
    		exit(1);
    	}
    
    
    	for(i=1; i<10; i++) {
    		fscanf(in, "%f%f%d", &lat[i], &lon[i], &value[i]);
    		
    		printf("%.3f %.3f %d\n", lat[i], lon[i], value[i]);
    	}
    
    	printf("\n\n");
    	i=5;
    	printf("%.3f %.3f %d\n", lat[i], lon[i], value[i]); //cheta 5-tia red
    
    	fclose(in);
    
    	return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You should take your EXCEEDINGLY large arrays off the stack, because you're running out of stack space.

    Most systems give you between 1 and 8MB of memory for the stack, which is usually sufficient for all but the most recursive of programs.

    A quick hack is
    static int large[1000000];

    A much better approach is to use dynamic memory (malloc etc)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File read in problem
    By DimensionX in forum C Programming
    Replies: 5
    Last Post: 12-02-2009, 12:37 PM
  2. read a file of commands and execute them
    By surlyTomato in forum C Programming
    Replies: 5
    Last Post: 08-20-2009, 11:32 AM
  3. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:39 AM
  4. Problem of read file in C++(hexagonal resp)
    By rosicky2005 in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2006, 11:35 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM