我寫一個程序來讀取記錄一個文件,提取一些網絡的視場爲VLA的,使用插入排序排序,使用二進制搜索搜索用戶SPECI網絡版目標並打印出結果。傳遞âgetGradesFromFileâ的參數1將指針整數,未作鑄
芽我不斷收到這些錯誤:
search.c: In function âmainâ:
search.c:57: warning: passing argument 1 of âgetGradesFromFileâ makes integer from pointer without a cast
search.c:19: note: expected âintâ but argument is of type âchar *â
search.c:57: warning: passing argument 2 of âgetGradesFromFileâ makes pointer from integer without a cast
search.c:19: note: expected âchar *â but argument is of type âintâ
search.c:57: warning: passing argument 3 of âgetGradesFromFileâ from incompatible pointer type
search.c:19: note: expected âint *â but argument is of type âchar *â
search.c:57: warning: passing argument 4 of âgetGradesFromFileâ makes integer from pointer without a cast
search.c:19: note: expected âintâ but argument is of type âint *â
search.c:57: warning: passing argument 7 of âgetGradesFromFileâ makes pointer from integer without a cast
search.c:19: note: expected âchar *â but argument is of type âintâ
search.c:57: error: too many arguments to function âgetGradesFromFileâ
search.c:59: warning: passing argument 1 of âprintArrayâ makes integer from pointer without a cast
search.c:38: note: expected âintâ but argument is of type âchar *â
search.c:59: warning: passing argument 2 of âprintArrayâ makes pointer from integer without a cast
search.c:38: note: expected âchar *â but argument is of type âintâ
search.c:62: error: expected expression before âintâ
search.c:62: error: too few arguments to function âinsertionSortâ
search.c:67: warning: comparison between pointer and integer
search.c:68: warning: comparison between pointer and integer
search.c:68: warning: comparison between pointer and integer
search.c:69: warning: passing argument 3 of âbinarySearchâ makes integer from pointer without a cast
search.c:33: note: expected âintâ but argument is of type âint (*)[60]â
search.c:69: error: too few arguments to function âbinarySearchâ
search.c:73: error: expected â(â before â{â token
這些錯誤的任何幫助表示讚賞!
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
void getGradesFromFile(int size,
char line[],
int studentI_D[],
int test1,
int test2,
int test3,
char grades[]);
void insertionSort(char list[],
int last);
void binarySearch(int size,
int studentID[],
int target,
char* locn);
void printArray(int size,
char list[*],
int studentI_D[*],
int test1,
int test2,
int test3,
char grades[*]);
int main(void)
{
char grades[60];
char str[60];
int size = sizeof(str)/sizeof(str[60]);;
int studentID [60];
char letter;
int exam1, exam2, exam3;
getGradesFromFile("grades.csv", size, str, studentID, exam1, exam2, exam3, grades);// function call
printf("The original numbers are:");
printArray(str, size, studentID, exam1, exam2, exam3, grades);
printf("\n\n");
printf("The sorted numbers are:");
insertionSort(int size, studentID, grades);// inscertion sort function call
printf("\n\n");
printf("Enter student ID and -1 to quit");
scanf("%d", studentID);
while (studentID != -1){
if (studentID > 99999 && studentID < 1000000){
binarySearch(size, studentID, &studentID);
}
else if {
printf ("Error and enter again [100000, 999999] and -1 to quit");
}
exit;
}
return 0;
} // end of main
void getGradesFromFile(int size,
char line[],
int studentI_D[],
int test1,
int test2,
int test3,
char grades[])
{
FILE* pData;
int i = 0;
if ((pData == NULL) {// opens file grades.csv
fprintf(stderr, "Error opening file %s.\n");// error handling statement
exit(1);
}
while (fgets(line,sizeof(line), pData) != NULL){
sscanf(line, "%25s, %d, %d, %d, %c", studentID[i], &test1, &test2, &test3,
grades[i]);
i++;
}
}
if fclose(pData) {
fprintf(stderr, "Error closing file %s.\n", filename);// close file
exit(2);
}
}
void insertionSort(int length, int studentID[], char grades[])
{
int i, key, key1, j;
for (i = 1; i < n; i++)
{
key = studentID[i];
key1= grades[i];
j = i-1;
while (j >= 0 && studentID[j] > key)
{
studentID[j+1] = studentID[j];
grades[j+1] = grades[j];
j = j-1;
}
studentID[j+1] = key;
grades[i+j] = key1;
}
}
void binarySearch(int size, int student[], int target, char *locn)
{
int first = 0;
int last = size - 1;
int mid;
bool found = false;
while (first <= last) {
mid = (first + last)/2;
if (target > list[mid]) {
first = mid + 1;
} else if (target < list[mid]) {
last = mid - 1;
} else {
*locn = mid;
found = true;
break;
}
}
return found;
}
void printArray(int size,
char A[size],
int studentI_D[size],
int test1,
int test2,
int test3,
char grades[size])
{
for (int i=0; i<size; i+=4) {// prints the array in four lines
printf("\n");
for (int j=0; j<4; j++) {
printf("%10.2f ", A[i+j]);
}
}
}
void flushScanf(void)
{
char c;
while((c = getchar() != '\n' && c != EOF)
;
}
您需要將前兩個參數切換在調用'getGradesFromFile'。您在調用其他函數時也犯過類似的錯誤。 –
感謝您的回覆,我修復了所有與我的getGradeFromFile函數有關的編譯錯誤。如果任何人都可以幫助我休息。 – josmar