LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-18-2023, 10:35 AM   #16
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323

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;
}
 
Old 12-18-2023, 10:37 AM   #17
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by Turbocapitalist View Post
Then the Lua based regexp module for C++ is described here:

http://www.gammon.com.au/forum/?id=11063
I have a better link:

https://en.cppreference.com/w/cpp/regex
 
1 members found this post helpful.
Old 12-18-2023, 11:17 AM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
Quote:
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);
 
Old 12-18-2023, 02:54 PM   #19
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by atjurhs View Post
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
 
Old 12-19-2023, 10:01 AM   #20
atjurhs
Member
 
Registered: Aug 2012
Posts: 316

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
WTHeck you doing math for?
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
 
1 members found this post helpful.
Old 12-19-2023, 12:40 PM   #21
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by atjurhs View Post
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does Gitea based Git servers doesn’t offer Git pulling direction when mirroring, but GitLab has both pulling and pushing directions? hd_scania Linux - General 1 04-01-2022 04:29 PM
Says Glib isn't installed! Help, I'm pulling out my hair! zzmartinj Linux - Software 3 07-24-2003 09:46 AM
Star office install on Slack 9. Pulling hair out! drjimstuckinwin Slackware 2 03-27-2003 03:30 PM
Pulling out hair again... Ludacris Linux - Networking 8 12-22-2002 01:21 AM
URghh!!! pulling out hair! Ùmegaflops Linux - Newbie 4 05-28-2002 04:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration