Computing.Net > Forums > Programming > Text Editor/Fstream c++ help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Text Editor/Fstream c++ help

Reply to Message Icon

Name: darkangel46
Date: March 25, 2004 at 15:15:01 Pacific
OS: Linux
CPU/Ram: 1.5ghz/256mb
Comment:

Hello all. I am having a small problem here. Im trying to code a text editor in c++ console. I have the majority of it done, but am running into a small problem. I was able to accept input(text), put it into a two-demensional array and store it in a text file. NOw i am on the part where the user will choose a row from the array and edit that line. I am having problems with IFSTREAM, taking in the text file text and displaying it exactly as it appears. I am able to get the text but for some odd reason whenever i enter a space between words, the IFSTREAM output displays this on a new line. I will include the code, any help appreciated.

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>

using namespace std;

char text[24][81];
char text1[24][81];
int row,col;
int counter;
int subscript_1; //row
int subscript_2;
int editrow;
int x;
int choice;

string end;

int main()
{
start:
system("cls");
cout<<"1.New";
cout<<'\n';
cout<<"2.Edit";
cout<<'\n';
cin>>choice;

if(choice==1)
{
system("cls");
ofstream example ("example.txt");

cout<<"Type EXIT to quit and save text.";
cout<<'\n';
cout<<'\n';
//prompt


for(subscript_1=0;subscript_1<24;subscript_1++)
{

gets(text[subscript_1]); //row will increment after they hit enter

if(text[subscript_1][0]=='E'&&text[subscript_1][1]=='X'&&text[subscript_1][2]=='I'&&text[subscript_1][3]=='T')
{

cout<<"Data saved to file.\n";
goto start;
}



example<<text[subscript_1]<<endl;//will put text into file

}

example.close();

}

if(choice==2)
{
for(subscript_1=0;subscript_1<24;subscript_1++)
{
if(text[subscript_1][0]=='E'&&text[subscript_1][1]=='X'&&text[subscript_1][2]=='I'&&text[subscript_1][3]=='T')
{
goto edit;
}

puts(text[subscript_1]);

}
}

edit: //edit

cout<<"\n\n";
ifstream example2;


example2.open("example.txt",ios::in);

for(subscript_1=0;subscript_1<24;subscript_1++)
{
example2>>text1[subscript_1];
puts(text1[subscript_1]);

}

example2.close();
return 0;
}
//no errors




Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


a map on a website Access Parallel Port



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Text Editor/Fstream c++ help

text editor programming www.computing.net/answers/programming/text-editor-programming/8531.html

VB6 Text Editor Title www.computing.net/answers/programming/vb6-text-editor-title/17522.html

borland C++5.02 text editor help www.computing.net/answers/programming/borland-c502-text-editor-help/5211.html