0
我很新的C語言編程,我不斷收到這些錯誤,我有沒有線索:警告:傳遞從兼容的指針類型「word_search」的參數1 [默認啓用]
HW5_mkhan44.c: In function ‘main’:
HW5_mkhan44.c:31:3: warning: passing argument 1 of ‘word_search’ from incompatible pointer type [enabled by default]
HW5_mkhan44.c:9:5: note: expected ‘char *’ but argument is of type ‘struct FILE **’
HW5_mkhan44.c:31:3: warning: passing argument 2 of ‘word_search’ from incompatible pointer type [enabled by default]
HW5_mkhan44.c:9:5: note: expected ‘char *’ but argument is of type ‘char **’
HW5_mkhan44.c:31:3: error: too many arguments to function ‘word_search’
HW5_mkhan44.c:9:5: note: declared here
而且,這裏是代碼:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int word_search(char word[100], char str[100]);
int character_count(char curr_str[100]);
void search_count(FILE *fpter, char c[100], int *len, int *result);
int main(void)
{
FILE *fileptr;
char filename[100];
char* word[100];
int *length;
int *num;
printf("Please input the text file name: ");
scanf("%s", filename);
fileptr = fopen(filename, "r");
if(fileptr == NULL)
printf("File does not exist");
else{
printf("Please enter a word to search: ");
scanf("%s", word);
word_search(&fileptr, word, &length, &num);
if(*num == 0){
printf("Word exists in file");
printf("There are %d characters in file", *length);
}
else
printf("Word does not exist in file");
}
fclose(fileptr);
return 0;
}
int word_search(char word[100], char str[100])
{
int num;
if(strcmp(word, str) == 0){
num = 0;
return(num);
}
else{
num = 1;
return(num);
}
}
int character_count(char current_str[100])
{
int word_length;
word_length = strlen(current_str);
return(word_length);
}
void search_and_count(FILE *fpter, char c[100], int *len, int *result)
{
char line[120];
while(fgets(line, sizeof(line), fpter)){
char* t = strtok(line, " ");
*len = wordsearch(c, t);
*result = character_count(t);
}
}
在此先感謝您。
我知道你是C的新手。但是看起來你有基本的錯誤,即使是新手也能看到你是否真的仔細檢查了你的代碼。例如,'int word_search(char word [100],char str [100]);'聲明一個帶有兩個參數的函數,然後用四個參數調用它:'word_search(&fileptr,word,&length,&num);'。 – kaylum
And remove '*'from char * word [100]; int * length; int * num;' – BLUEPIXY
編碼時,縮進一致,不要使用製表符縮進。縮進後每個大括號'{'。unindent before every closing括號'}'。爲每個縮進級別建議使用4個空格不要使用製表符,因爲每個文字處理器/編輯器的製表位/製表符寬度設置不同 – user3629249