[C++] Help simplifying massive nested conditional.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[C++] Help simplifying massive nested conditional.
Hi, I'm fairly new to C++, and I'm still learning the ropes. My problem is I'm building a little program to print to stdout values I've obtained through string manipulation of iwconfig output. The problem is that in order to make sure I work around some odd behaviour which I've seen I've had to do 5 separate "if file exists" checks with the following code:
As you can see, this is a godawful mess, and I was just wondering if anybody had any ideas on clearing it up. I'm using the following to check for the files' existence. Something like being able to use wildcards in the FileExists function is exactly what I'm looking for.
Code:
bool FileExists(string strFilename)
{
struct stat stFileInfo;
bool blnReturn;
int intStat;
// Try to get file attributes
intStat = stat(strFilename.c_str(), &stFileInfo);
if(intStat == 0)
{
// File exists because we got the attributes
blnReturn = true;
}
else
{
blnReturn = false;
}
return(blnReturn);
}
being able to use wildcards in the FileExists function is exactly what I'm looking for.
I think the earlier responders missed that in your post.
That's what you want, so that is what you should have asked for clearly, instead of burying it in a post that seems to ask something else.
I've done that (wild card in a similar FileExists function), but long ago and don't recall even the function name to search for. But I don't think it's hard. Ask clearly and I think someone else will remember the answer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.