Thread: I need help fixing a warning

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    7
    Here's the part that I updated, everything else remained the same.

    Code:
    void get_input (address_record* addresses[], int* nr_addresses)
    {
        int k;
        char file_name[1000];
        FILE* pAddressFile;
        address_record* pA;
        
        printf("Input file: ");
        scanf("%999[^\n]", file_name);
        
        pAddressFile = fopen(file_name, "r");
        
        if(pAddressFile == NULL)
        {
            fprintf(stderr, "Error trying to open %s to read file.\n", file_name);
            abort();
        }
        
        for(k = 0; k < MAX_RECORDS; k++)
        {
            addresses[k] = malloc(sizeof(address_record));
        }
    }
    So from here, I would use fgets inside (or outside?) of the loop to get each line from the file and from there use sscanf to get each of the parts of the line and store each of them in the struct members? Also, what do you mean by tokense and tokenising? I don't remember my teacher talking about this.

    Edit*
    One more question. My program has to be able to read 200 records. So would I need to multiply the sizeof in malloc by 200 or is it already taken care of by the address[k] assignment?
    Last edited by Nterpol; 04-13-2006 at 08:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM