我已经在这里阅读了几个小时的类似问题,而我似乎无法得到它。我对java很有经验,但这是我在C中的第一个项目。教授完全没有教我们这个项目的相关技能。
程序目的:从文本文件中一次读取一对文本行,并根据ASCII整理顺序确定第一个是否等于,大于或小于第二个。程序还将指示出现第一个偏差的字符位置。程序将处理所有线对,然后打印处理的对的总数,即数字 等对,第一行的数量大于第二行,第一行的数量小于第二行的数量。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void readFile(char **strs){
//read strings from file and place them in strs
}
void comparePairs(char *strs, int *nums){
//compares pairs of strings according to ASCII collating sequence,
//printing strings as it goes. Also prints the position of the first deviation
//between a pair, if there is any.
//returns numPairs, numEqual, numGreater, and numLesser
int numPairs = 0;
int numEqual = 0, numGreater = 0, numLesser = 0;
nums[0] = numPairs;
nums[1] = numEqual;
nums[2] = numGreater;
nums[3] = numLesser;
}
void printResults(int numPairs, int numEqual, int numGreater, int numLesser){
printf("%d pairs were processed.\n", numPairs);
printf("%d equal pair(s).\n", numEqual);
print("%d greater pair(s).\n", numGreater);
print("%d less than pairs(s).\n", numLesser);
}
int main(){
char strs[100][1000];//strings from file (max 100 strings, each of max size 1000)
char (*ptrStrs)[1000];
ptrStrs = strs;
int nums[4] = {0,0,0,0};//contains numPairs, numEqual, numGreater, and numLesser
int numPairs = 0;//the total number of pairs processed
int *ptrNumPairs = &numPairs;
//the number of pairs where the first line is equal to, greater than, or lesser
//than the first line respectively
int numEqual = 0, numGreater = 0, numLesser = 0;
int *ptrNumEqual = &numEqual, *ptrNumGreater = &numGreater, *ptrNumLesser = &numLesser;
readFile(**strs);
comparePairs(strs, nums);
printResults(nums[0], nums[1], nums[2], nums[3]);
return 0;
}
我收到很多错误,但第一个是passing argument 1 of 'readFile' makes pointer from integer without a cast
。任何有助于取得一些进展的帮助将不胜感激。