C and Cpp

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDesktop ProgrammingC and Cpp

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old July 23rd, 2008, 07:54 PM
rocky11 rocky11 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 1 rocky11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 35 sec
Reputation Power: 0
File handling using streams !!!

I have this program : which reads one by one line by line from a txt file and modifies a line at a position after the line whr "ths " occurs in the file to be modified. For each line it reads it modifies in the given file at that location and creates a file with rest of content same naming file as page1.txt , for 2nd line it reads and modifies in the given file at same location it creates a file wid same content naming page2.txt and it continues...... till all the lines of other file from which each line is read and modified in given file ends .

But my problem is i want this code to be modified such that at the same location in file to be modified i want to read first line from file and change as previosly done and then read one more line from another txt file and change one more line after the previously modified line. i.e same operation as this . but 2 lines i wanna modify one read from 1st file and 2nd from 2nd file ( in both same line numbered file ) and modify it after the line whr "ths" occurs .and the naming and all will continue.



Can someone help me in modifying this one or with a program to do this .. i did this in unix . I donno whether i can use some other framework to do this.. which would be helpful to me . !!

Thanks !!!



#include<string.h>
using namespace std;
ifstream infile1;
ifstream infile2;
ofstream outfile;
char *line,*line1,*line2,*line3;
char *str,*num;
int par=0,i=0;
int main(char argc, char * argv[])
{

infile1.open(argv[1]);
infile2.open(argv[2]);
std:stringstream sin;
line=new char[100];
line1=new char[100];
line2=new char[100];
line3=new char[100];
str=new char[30];
num=new char [30];
cout<<"enter"<<endl;
while(!infile2.eof())
{
i++;
sin.str("");
infile1.clear();
infile1.seekg(0,ios::beg);
sin << i;
std:tring val(sin.str());
cout<<"i: " <<val<<endl;
std:tring val1;
val1 = "page"+val+".txt";
outfile.open(val1.c_str());
while(!infile1.eof())
{
infile1.getline(line,100,'\n');
cout<<"line: "<<line<<endl;
strcpy(line2,line);
str=strtok(line," ");

while((str=strtok(NULL," "))!=NULL)
{
cout<<"str:"<<str<<endl;
if(strcmp(str,"ths")==0)
{
outfile<<line2<<"\n";
infile1.getline(line,100,'\n');
infile2.getline(line1,100,'\n');
outfile<<line1<<"\n";par=1;
cout<<"done :"<<i<<endl;
}
}
if(par==0)
outfile<<line2<<"\n";
par=0;
}
cout<<"line1: "<<line1<<endl;
outfile.close();
}
infile1.close();
infile2.close();
}

Reply With Quote
Reply

Viewing: Tutorialized ForumsDesktop ProgrammingC and Cpp > File handling using streams !!!


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap