Thread: help whit file opening

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    1

    help whit file opening

    HI i'm new to C programming and i wanted to ask where the error is in that part of code it is supposed to open a .txt file placed in the same folder and print the numbers that it contains onto the screen but i'm reciving a segmentation fault; I'm using the Xcode compiler that's embedded in an apple developers pack...

    that's the code...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main() {
    	FILE *file;
    	int numbers[3000]; 
    	int i,j;
    	
    	file = calloc(3000, 10);
    	
    	file = fopen("numeri.dat", "r+");
    	
    
    		printf("File opened successfully.\n");
    		
    		i = 0 ;    
    		
    		while(!feof(file)) { 
    			
    			fscanf(file, "%d", &numbers[i]);
    			i++;
    		}
    		
    		printf("The numbers are:\n");
    		
    		for(j=0 ; j<i ; j++) { 
    			printf("%d\n", numbers[j]);
    		}
    		
    		fclose(file);
         	free(file);
    		return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM