Ok I'm working on a class project for C programming and I'm having problems opening 2 data files I need. When I execute the code it gives me the error opening files message.
To execute I've been getting into the proper directory and then typing
finalproject population path
finalproject is the name of the .exe file
population and path are 2 seperate text files I need to open and scan into the program
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define FILENAME "h:\\destruction.txt"
int main(int argc, char *argv[])
{
int i,c,d;
for(i=0;i<argc;i++)
printf("arg %d: %s\n", i, argv[i]);
FILE *population = fopen(argv[1],"r");
if(population==NULL)
printf("Error opening population matrix file, try again \n");
else
{
while((c=getc(population))!=EOF)
putchar(c);
}
FILE *path=fopen(argv[2],"r");
if(path==NULL)
printf("Error opening path matrix file, try again \n");
else
{
while((d=getc(path))!=EOF)
putchar(d);
}
int a,b;
int destruction[5][5];
FILE *des;
printf("\nDestruction matrix is as follows\n");
if((des=fopen(FILENAME,"r"))==NULL)
printf("The file was not opened, HAHA\n");
for(a=0;a<5;a++)
fscanf(des,"%d %d %d %d %d",&destruction[a][0],&destruction[a][1],&destruction[a][2],&destruction[a][3],&destruction[a][4]);
/*print out the destruction matrix*/
for(a=0;a<5;a++)
{
for(b=0;b<5;b++)
printf("%d ",destruction[a][b]);
printf("\n");
}
}
Any help or suggestions would be greatly appreciated.
Thanks