I need help fixing a warning
Hi guys,
I'm a beginner in C and need help with my project for school. Here's my code,
Code:
/* -------------------------------------------------------
* Carpooling
* -------------------------------------------------------
* This program will read a file that contains records of
* people's addresses and will group the records together
* based on the home zip code and work zip code.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#define MAX_RECORDS 200
typedef struct
{
char* last_name;
char* first_name;
char* address;
char* city;
char* state;
int home_zip_code;
int work_zip_code;
}address_record;
/* Extract the next field from the string passed by the caller.
* The field is delimited by either a comma or the end of the
* string */
char* next_field (char* pStart)
{
char* pComma;
int length;
char* pField;
pComma = (char*) strchr(pStart, ',');
if (pComma == NULL)
{
length = strlen(pStart);
}
else
{
length = pComma - pStart;
}
pField = (char*) calloc (1, length+1);
assert (pField != NULL);
strncpy(pField, pStart, length);
return pField;
}
/* This function reads address records in the form of comma
* separated values from a file specified by the user and
* sets up a dynamically allocated address record struct for
* each record. It puts pointers to the address record structs
* into the array passed by the caller.
* The caller specifies length of the array in nr_address.
* This function sets nr_addresses to the number of array entries
* actually filled.
*/
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] = fscanf(pAddressFile, "%s,%s,%s,%s, %s,%d,%d\n",
pA->last_name, pA->first_name, pA->address,
pA->city, pA->state, &pA->home_zip_code,
&pA->work_zip_code);
}
}
/* Sort an array of pointers to address records according to
* home zip code and work zip code.
*/
void sort_by_zip_code (address_record* rec[], int length)
{
}
/* Output blocks of address records that have the same home
* and work zip code.
*/
void output_matches(address_record* addresses[], int length)
{
}
int main()
{
int nr_addresses = MAX_RECORDS;
address_record* addresses[MAX_RECORDS];
get_input(addresses, &nr_addresses);
/*sort_by_zip_code(addresses, nr_addresses);
output_matches(addresses, nr_addresses);*/
return 0;
}
Now my problem is that I keep getting this error from the compiler,
Quote:
warning: assignment makes pointer from integer without a cast
It appears to be coming from my for loop in my get_input function or atleast that's what the (Unix) compiler says. Could someone point me in the direction to fix this? Maybe a website or a hint on what I'm doing wrong would be great.
Any help is appreciated. Thanks! :)
-Nterpol
Edit: Would it be a better idea to get each of the item individually from the file? If so, do I need a loop to do it?