2 Replies - 289 Views - Last Post: 19 September 2012 - 12:16 AM Rate Topic: -----

#1 raghvendra26  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-September 12

please any 1 help me i try to read from a text file from new line.

Posted 18 September 2012 - 11:59 PM

// file.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
class test
{
public:
	char a[100],c[100];						

	int i,len;
	void readdata(void);
	void writedata(void);
	void revarray(void);   
};
void test::readdata()
{
	cout<<" This is from file ATC\n\n";
	ifstream read;
	read.open("atc.text",ios::in);
	read.getline(a,'\n');
	len=strlen(a);
	cout<<a<<"\n";
	read.close();
}
void test::revarray()
{
	cout<<"Reverse of info\n";
    i=len-1;
	do
	{
		c[(len-i)-1]=a[i];
		cout<<a[i];
		i--;
		
	}
	
	while(i>=0);
		
	cout<<"\n";
}
void test::writedata()
{
	cout<<"All read Info copyed in result file\n";
	ofstream write;
	write.open("test2.text",ios::out);
	write<<c;
	write.close();
}
int main() 
{
	test data;
	data.readdata();
	data.revarray();
	data.writedata();
	
	
}

This post has been edited by Salem_c: 19 September 2012 - 12:02 AM
Reason for edit:: added [code][/code] tags - learn to use them yourself


Is This A Good Question/Topic? 0
  • +

Replies To: please any 1 help me i try to read from a text file from new line.

#2 raghvendra26  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-September 12

Re: please any 1 help me i try to read from a text file from new line.

Posted 19 September 2012 - 12:06 AM

// file.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
class test
{
public:
	char a[100],c[100];						

	int i,len;
	void readdata(void);
	void writedata(void);
	void revarray(void);   
};
void test::readdata()
{
	cout<<" This is from file ATC\n\n";
	ifstream read;
	read.open("atc.text",ios::in);
	read.getline(a,'\n');
	len=strlen(a);
	cout<<a<<"\n";
	read.close();
}
void test::revarray()
{
	cout<<"Reverse of info\n";
    i=len-1;
	do
	{
		c[(len-i)-1]=a[i];
		cout<<a[i];
		i--;
		
	}
	
	while(i>=0);
		
	cout<<"\n";
}
void test::writedata()
{
	cout<<"All read Info copyed in result file\n";
	ofstream write;
	write.open("test2.text",ios::out);
	write<<c;
	write.close();
}
int main() 
{
	test data;
	data.readdata();
	data.revarray();
	data.writedata();
	
	
}




hi I wnat to read from a text file line by line like...Ramesh
Mohan
Amit
Sunita
Ritu
...then reverse it and store in a array.. please anu one help me
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1766
  • View blog
  • Posts: 3,422
  • Joined: 30-May 10

Re: please any 1 help me i try to read from a text file from new line.

Posted 19 September 2012 - 12:16 AM

So what do you see at the moment?

Some random crash?
test2.text with nothing in it
test2.text with garbage in it
test2.text with the original string
test2.text with the reversed string and some garbage?

Start learning how to analyse and fix your own code.
You can't get away with write it and dump it on a forum for someone else to fix in the long run.

Since it seems you're using visual studio, perhaps you could use the debugger.
Start with a breakpoint on line 55, then investigate how to examine data and single-step the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1