I need to write a function parse_in with the following prototype :
int parse_in(FILE *f, int *cost[][]){
/* parse the input file and fill in const array
* Need to return the number of cities read in from the file
* Need to alloca memory for cost
*/
}
Using this function, I need to allocate memory for cost, read nxn lines, fill in cost and return n where n is the number of cities.
I will open the input file, input.txt in main before using this function.
Can you help me on it..
The code to open the input file is:
int main()
{File *in,*out;
int i ,n;
char buffer[100];
int ch;
char c;
in = fopen("input.tx t","r");
fgets(buffer, 10, in);
n = atoi(buffer);
printf("Number of Cities: %d \n\n", n);
while(!feof(in) )
{
c = fgetc(in);
printf("%c",c);
}
fclose(in);
getchar();
return 0;
}
can you guide me on it please.?
I need to do this for travelling salesman problem.
int parse_in(FILE *f, int *cost[][]){
/* parse the input file and fill in const array
* Need to return the number of cities read in from the file
* Need to alloca memory for cost
*/
}
Using this function, I need to allocate memory for cost, read nxn lines, fill in cost and return n where n is the number of cities.
I will open the input file, input.txt in main before using this function.
Can you help me on it..
The code to open the input file is:
int main()
{File *in,*out;
int i ,n;
char buffer[100];
int ch;
char c;
in = fopen("input.tx t","r");
fgets(buffer, 10, in);
n = atoi(buffer);
printf("Number of Cities: %d \n\n", n);
while(!feof(in) )
{
c = fgetc(in);
printf("%c",c);
}
fclose(in);
getchar();
return 0;
}
can you guide me on it please.?
I need to do this for travelling salesman problem.
Comment