code này mình muốn dùng hàm strstr() để kiểm tra có từ “FEMALE” nào trong mỗi mảng không
nhưng mà nó đều ra cả 5 “FEMALE” —có gì đó sai sai
ai giúp mình với ạ :((((
#include <iostream>
#include <string.h>
bool FEMALE(char *all_student,int index){
char *p1=strstr(all_student+index,"FEMALE");
if(p1==NULL)
return false;
else
return true;
}
int main(){
char **all_student=new char*[5];
for (int i=0;i<5;i++){
*(all_student+i)=new char[255];}
strcpy(*(all_student+0),"SV1;OBAMA;MALE");
strcpy(*(all_student+1),"SV2;YANJMAA,FEMALE");
strcpy(*(all_student+2),"SV3;TRUMP;MALE");
strcpy(*(all_student+3),"SV4;PUTIN;MALE");
strcpy(*(all_student+4),"SV5;PEREIRA;FEMALE");
for(int i=0;i<5;i++){
std::cout<<*(all_student+i);
std::cout<<"\n";
}
int dem=0;
for(int i=0;i<5;i++){
if(FEMALE(*(all_student),i))
dem++;
}
std::cout<<"\nhas "<<dem<<" FEMALE";
return 0;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?