473,698 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please help which checking no of seats in the flat file ".txt"

8 New Member
i have a .txt file which contains line of string like the below format
|111|34 sdddd| ppppp| A/C| 32| sadfd|
|4324|23 mmm| yyyyy| A/C|32| fdfffdfd|

the sixth column is the no of seats column where when i check the status of that particulat bus no 4324 it is displaying that the "seat is not available" and "available seats are 0"

In this code snippet i
i face the above problem in the "temp" variable.
please help me out.





void passenger::tran saction(string bus_no,int tkt,string passenger_name, int age,string journey_date,in t seat,int totalprice)
{ int temp;
string tempval,token,l ine;
stringstream iss;
int flag,flag1;
size_t found;
size_t found1;
fstream file("transacti on.txt",ios::in );
fstream file1("t.txt",i os::out);
while(getline(f ile,line))
{
found=line.find (journey_date);

if(int(found)>0 )
{
found1=line.fin d(bus_no);
if(int(found1)> 0)
{
iss<<line;
while(getline(i ss,token,'|'))
{
tempval=token;
}
temp=atoi(tempv al.c_str());
if(temp<seat)
{
cout<<"\t\tSorr y! Seats Not Available Now.."<<endl;
cout<<"Availabl e Seats are "<<temp<<en dl;
}
else if(temp==0)
{
cout<<"Sorry! Seats Fully Booked"<<endl;
}
else
{
temp=temp-seat;
std::string s;
std::stringstre am out;
out<<temp;
s=out.str();
line.replace(15 ,2,s);
cout<<"****Tick et Successfully Booked***"<<end l;
Aug 10 '08 #1
2 1697
donbock
2,426 Recognized Expert Top Contributor
i have a .txt file which contains line of string like the below format
|111|34 sdddd| ppppp| A/C| 32| sadfd|
|4324|23 mmm| yyyyy| A/C|32| fdfffdfd|

the sixth column is the no of seats column where when i check the status of that particulat bus no 4324 it is displaying that the "seat is not available" and "available seats are 0"
Not sure I understand the problem you're trying to solve. The sixth column of the first two records are " sadfd" and " fdfffdfd". In what way are these strings interpreted as number of seats? The fifth column ("32" and "32") look more appropriate.

By the way, it is helpful to enclose your source code in [code] tags.
Aug 10 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
You might read this article: http://bytes.com/forum/thread660060.html.

It shows how to build a parser to extract words froim a buffer. Just exactly what you are trying to do. Complete with code.
Aug 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
14253
by: Nicolas Girard | last post by:
Hi, Forgive me if the answer is trivial, but could you tell me how to achieve the following: {k1:,k2:v3,...} --> ,,,...] The subtle point (at least to me) is to "flatten" values that are lists. Thanks in advance,
6
1896
by: Uwe Mayer | last post by:
Hi, when extending a build in class, what does the constructor __init__(...) have to return? and how does the constructor call its base-class construtor? (or is this done automatically?) I want to derive from "file" to create a class that reads record from a binary file:
11
2165
by: David Morgenthaler | last post by:
How does one overide the iterator implied by the construct "for line in file:"? For example, suppose I have a file containing row,col pairs on each line, and I wish to write a subclass of file that will transform these to x,y coordinates using an affine transform. I'd like it to look something like this (but this clearly doesn't work): class myFile(file): def __init__(self,name,affine):
10
3714
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or bug? Can someone excellent to tell me the reason. best wishes
2
28569
by: Matt | last post by:
If I do the following, the browse text box still cannot see C:/hello world/test.txt. <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Any ideas? and workarounds to this problem? thanks!!
7
2668
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine if I use the web test interface. It also works fine if I call it from an ASP.NET page that has a text box where the XML is pasted and then passed on. However, I get an exception if I use an <input type="file"> control on the ASP page that allows...
3
2750
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: <DOCUMENT> ...... ...... some lead elements ...... <SEGMENT_LIST>
15
1818
by: Richard | last post by:
Can anyone recommend a good online resource listing all C keywords, standard system calls, defines etc in a "flat" hierarchy. I wish to set up some bindings in order to bring up "hints and tips" on using such keywords/functions from ISO C in an IDE I am working on. So I would bring up a function and use the current word as the search criteria to locate an online library/faq e.g
3
2927
blazedaces
by: blazedaces | last post by:
I've taken a look at the class and you only seem to be able to set the file name, but not it's save type. Why is this? Here's some code if you want it, but it doesn't seem to have a method for choosing the type of file to save: public void save(double x, double y) { FileDialog fd = new FileDialog(new Frame(), "Choose a text file to save to...", FileDialog.SAVE); fd.setFile("*.txt");
0
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.