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.
When you read the data from the file, it's a string. Leave it as a string. And you don't need a regular expression; you just need a substring search.
Code:
#include <iostream>
int main()
{
std::string number{"120027000"};
if (number.rfind("27") < number.length() - 3)
{
std::cout << "It has a 27 in the right place\n";
}
return 0;
}
When you read the data from the file, it's a string.
Not necessarily, granted we don't know how the OP is reading data from the file but you can easily read from an ASCII file as integers with spaces as a separator.
Quote:
int a,b,c,d;
fscanf(file,"%d %d %d %d",&a, &b, &c, &d);
NevemTeve and Michaelk, thank you very much! surprisingly simple. i was doing the division and the mod in the wrong order and i didn't know that the % sign in c++ means mod. i've got a lot to learn in c++ guess i could have found that on google
WTHeck you doing math for?
ASCII string, pull out one line as a time into a char buffer, use a char * to point to [2] and [5] check if they're zeros.
If so, pull out [3][4] otherwise continue and stop at EOF
i'm doing math because it's the only way i know how to begin to write the code - i'm a complete beginner at this coding stuff, please be nice.
the problem has been solved at this thread can be closed
Yeah sorry not intending to insult. Just exasperation at the overdone method.
Threads are not closed, replies can come at any future point, but usually people will leave old threads alone.
For learning purposes my suggestion is to consider multiple solution concepts, a very common point that sent me down frustration holes in early programming was single focus that my original concept to solve something was "the way", once you witness others solve things differently you begin to realize that your first instinct may not always be the right choice. There can be numerous "right" choices.
The syntax is easy, it's how you solve it which is the art form. And I hope you embrace that mindset, is my input here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.