473,382 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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::transaction(string bus_no,int tkt,string passenger_name,int age,string journey_date,int seat,int totalprice)
{ int temp;
string tempval,token,line;
stringstream iss;
int flag,flag1;
size_t found;
size_t found1;
fstream file("transaction.txt",ios::in);
fstream file1("t.txt",ios::out);
while(getline(file,line))
{
found=line.find(journey_date);

if(int(found)>0)
{
found1=line.find(bus_no);
if(int(found1)>0)
{
iss<<line;
while(getline(iss,token,'|'))
{
tempval=token;
}
temp=atoi(tempval.c_str());
if(temp<seat)
{
cout<<"\t\tSorry! Seats Not Available Now.."<<endl;
cout<<"Available Seats are "<<temp<<endl;
}
else if(temp==0)
{
cout<<"Sorry! Seats Fully Booked"<<endl;
}
else
{
temp=temp-seat;
std::string s;
std::stringstream out;
out<<temp;
s=out.str();
line.replace(15,2,s);
cout<<"****Ticket Successfully Booked***"<<endl;
Aug 10 '08 #1
2 1673
donbock
2,426 Expert 2GB
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 Expert Mod 8TB
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
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...
6
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...
11
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...
10
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...
2
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...
7
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...
3
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: ...
15
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"...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.