I'm checking the string for alphanumeric characters and want to build a file system.
I've tried using the Fnameisaln recursively but it is giving me an invalid pointer, Aborted(core dumped error).
On debugging- "Program received Signal SIGABRT, aborted"
Maybe I can't modify the member string twice? Is there a rule like that?
class File
{
public:
std::string n;
File(char str[]) {
n = Fnameisaln(str);
}
std::string Fnameisaln(char a[]);
};
std::string File::Fnameisaln(char b[]) {
int i = 0;
bool isaln = false;
while(b[i]!='\0'){
if(isalnum(b[i])) {
isaln=true;
i++;
std::cout<< "\nWorking\n";
}
else {
isaln=false;
std::cout << "Warning!\n";
break;
}
}// (while loop for checking if alphanumeric)
if(isaln) {
std::string s = b;
std::cout << "\n W2 \n"; // to check if working
return s;
}
else {
std::cout << "Please enter file name again-\n";
std::cin >> b;
n.assign(Fnameisaln(b)); // n=Fnameisaln(b) also tried
}
}
Expected - Checks Filename for alphanumeric characters and returns only when true.
Actual - Not returning when alphanumeric (still warns when I enter a character like '&' in the name)