שאלה ב- c

ושוב שגיאה

זו הפונקציה שלי:



#define MAX_LENGTH 100

int main(int argc, char **argv) {
int i;
int size=5;
char *strs[size];
for (i=0; i<size; i++){
strs = (char*)malloc(sizeof(char)*MAX_LENGTH);
printf("Please enter string: ");
scanf("%s", strs);

}
filtering(strs, size, getInt);

return 0;
}



והוא נותן לי את הוורנינג הזה:

warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat]


מה אני צריכה לשנות?

תודה!
 
שיניתי :)

מסתבר שהייתי פשוט צריכה להוסיף מצביע (להוסיף כוכבית..)

תודה!!

הבעיה שלי עכשיו היא עם הפונקציה פילטרינג . היא מאורה לעשות את זה:
Write a filter function FILTERING with the following specification:
Receives 3 arguments: an array of pointers (to char*), the size of the array, and a pointer "f" to a function that receives a char* argument and returns int.
The pointer to a function of this type is declared as follows: int (*func)(char*);
Description:FILTERING applies the function pointed to by "f" to each of the elements of the array, and prints the elements for which the function returns a number greater than 4.

זו הפונקציה שלי:


void filtering (char* pointers[] , int size, int(*f)(char*)){
int i;
int num;
for (i=0; i<size; i++){
num=f (pointers);
if (num>4)
printf("printing %s ", pointers);
}

}



וזה הדפיס לי רק את המילה האחרונה שהכנסתי...
מה לא תקין?
 
מה זאת אומרת?

מה זאת אומרת מה נאמ עושה?

אני צריכה שהפונקציה שלי תעשה את זה:

Write a filter function FILTERING with the following specification:
Receives 3 arguments: an array of pointers (to char*), the size of the array, and a pointer "f" to a function that receives a char* argument and returns int.
The pointer to a function of this type is declared as follows: int (*func)(char*);
Description:FILTERING applies the function pointed to by "f" to each of the elements of the array, and prints the elements for which the function returns a number greater than 4.

כלומר, כל מילה שאורכה מעל 4 שתדפיס אותה...
אבל היא מדפיסה לי רק את המילה האחרונה שהכנסתי ולא את כולן.
זו הפונקציה getInt שלי שפילטרינג משתמשת בה:


|קוד|
int getInt(char* sentence){
int count=0;
int i;
char *mishpat = (char*) malloc(sizeof(*sentence));
mishpat= strcpy(mishpat, &sentence[0]);
for (i=0; i<strlen(mishpat); i++){
if ((mishpat!=' ') && (mishpat!='\0' ))
count++ ;
}
return count;
}



איך אני יכולה לגרום להם לבצע את מה שמבקשים בשאלה?

תודה!
 
למעלה