Urgent help

This is a discussion on Urgent help within the C Programming forums, part of the General Programming Boards category; i need to submit a program in 2 hours and im stuck. i need to read a file and put ...

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

    Urgent help

    i need to submit a program in 2 hours and im stuck.
    i need to read a file and put it in a array so it can be used later and i got
    Code:
    void comando_read_file()
    {
    	FILE *f;
    	int i;
    	char figuras[MAX_SIZE];
    		if ( ( f = fopen ("flatland.txt", "r" ) ) == NULL ) {
      perror ( "error openning the file" );
      exit ( 0 );
    }
    	 for ( i = 0; fgets ( figuras, MAX_SIZE, f ) != NULL; i++ ) {
        figuras[i]=fputs(figuras, stdout);}
    	fclose (f);
    }
    also the program is about making circles and squares the file has this type of text:
    NC 100 100 30 4
    NS 300 300 40 40 3
    ....

    NC - new circle
    NR - new square
    first 2 numbers are the centre points
    the 30 is the raidius and 40 40 is the weith and lenght
    4 and 3 is the color

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    31
    It you want to use the data in the array after this function returns then you need to define
    the array with a more global scope. (see Scope rules in you C book)

    e.g.

    char figuras[MAX_SIZE];

    void comando_read_file()
    {
    ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Minimax, URGENT :(
    By Dark-MX0Z in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2007, 06:29 AM
  2. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 10:38 PM
  3. Help Needed: Borland C++ 5.5 Installation - URGENT!
    By Linette in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2002, 06:44 PM
  4. help... urgent,... thanks!
    By weihann in forum C Programming
    Replies: 6
    Last Post: 02-28-2002, 10:17 PM
  5. Help.... Urgent... Thanks!
    By weihann in forum C Programming
    Replies: 0
    Last Post: 02-27-2002, 10:15 PM

Tags for this Thread


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