In this program, i want to let user to input 2 arguments, the number of integer,and the file name.
- the file has 10 lines of integer value.
- read the file, and put it to inArray[];
and then output it as the end;
notes: For the complete program, i want to make a program that will scan a file consists of random integer,and then sort them in ascend order, and print out the first 10 percent of the sorted integer.
Error: For now, i want to test if it can read the file and put values into the inArray properly, but its keep getting errors.
warning: initialization makes integer from pointer without a cast findTotal.c:43:6: warning: passing argument 1 of ‘fopen’ makes pointer from integer without a cast /usr/include/stdio.h:271:14: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
Please help me with this, thank you
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
int numOfInt;
char fileName="";
sscanf(argv[1],"%d",&numOfInt);
sscanf(argv[2],"%c",&fileName);
int i, rc;
/* the origninal list , initialise as 0 index*/
int inArray[numOfInt];
/* the number of output int */
int outNumInt = numOfInt * 0.1;
/* the output array of int */
int outArray[outNumInt];
FILE *inFile;
inFile = fopen(fileName,"r");
/* check if the file is empty */
if(inFile==NULL){
printf("can not open the file");
}
for (i = 0; (rc = getc(inFile)) != EOF && i < numOfInt; inArray[i++] = rc)
{
}//for
fclose(inFile);
for(i = 0; i < numOfInt;i++){
printf("%x\n",inArray[i]);
}
}//main