can anyone help me with my code? I don't understand where its making such problem. my code is to check if a given string is valid variable or not. My checkIdentifier function should return false for some cases and true for some cases but its only return false. my input is abcd and its will print valid but when my input is abcd# its will print invalid
#include<bits/stdc++.h> #include<strings.h> using namespace std; string ishfakur; void getInput(){ cin>>ishfakur; } bool checkKeyword(){ string keyword[32]={ "auto","double","int","struct","break","else","long", "switch","case","enum","register","typedef","char", "extern","return","union","const","float","short", "unsigned","continue","for","signed","void","default", "goto","sizeof","voltile","do","if","static","while" } ; for(int i=0;i<32;i++){ if(ishfakur==keyword[i]){ return true; } } } bool checkIdentifier(){ if(ishfakur.length()>=30 || ishfakur.at(0)<='9' || strstr(ishfakur.c_str(),"#") || checkKeyword()==true) return false; else return true; } void giveOutout(bool st){ if(st==true){ printf("valid"); } else printf("invalid"); } int main(){ bool status; getInput(); status = checkIdentifier(); giveOutout(status); }