在这个程序中,我想让用户输入 2 个参数,整数个数和文件名。
- 该文件有 10 行整数值。
- 读取文件,并将其放入 inArray[];
然后将其作为结尾输出;
笔记:对于完整的程序,我想制作一个程序,它将扫描由随机整数组成的文件,然后按升序对它们进行排序,并打印出排序整数的前 10%。
错误:现在,我想测试它是否可以读取文件并将值正确放入 inArray,但它不断出错。
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’
请帮我解决这个问题,谢谢
#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