0

Help please

#include <iostream> #include <string.h> using namespace std; int main() { char s[30]="",*p,h[2]=""; int q=0; cin>>s; p=s; if(strcspn(p,"x")<strlen(p)){strcpy(h,"c");} else strcpy (h,"d"); while(strcspn(p,h)<strlen(p)) { q++; } cout<<q; return 0; } What did I write wrong? We need to count the number of c symbols, if there is letter x, otherwise, the number of letters d

21st Jun 2023, 4:47 PM
Vahram Petrosyan
1 Réponse
+ 2
Seems like the while loop is gonna be infinite (or skipped), no? strcspn doesn't actually mutate p here so it'll just stay true (or be false to begin with if there are none)
21st Jun 2023, 7:09 PM
Orin Cook
Orin Cook - avatar