Thread: How to make a Text Editor???!!

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    43

    Exclamation How to make a Text Editor???!!

    I just begginer in the c++.... I tried to make s poor program, that read text and store it in a stuct and desplay it on the screan, and when the user want he can save it, But I didn't success I don't know exactly how to save, and I have problem with the struct when I pass it to function... Can you help Me finish this attempt.
    -------
    Code:
    #include<iostream.h>
    #include<fstream.h>
    #include<conio.h>
    char FLN;
    static int i;//To count the letters
    struct page{
           char pages[40][100];
           };
    
    
    int Save(struct page X);
    void main(void)
    {
    clrscr();
    int L=1,C=1,CC=1,LL=1;   //L=line,C=character,CC=character 
    //in the array,LL=Line in the array1,
    
    struct page P1;
    while(1)
    	{
    P1.pages[L][C]=getch(); // put the char the I recieve in the array
    	
    if(C==80){C=1;L++;} //New Line
    	if(P1.pages[L][C]==(char)13){L++;C=1;cout<<endl;continue;}//When Enter:New Line
    
    	if(P1.pages[L][C]==19){Save(P1);continue;}//Ctrl+S to 
    //save
    
    	if(P1.pages[L][C]==char(27))break;//Esc Exits
    	
     if(P1.pages[L][C]==char(8)){C--;gotoxy(C--,L);cout<<" ";i-=2;if(C==1)C=1;}//when backSpace, do backspace!
    
    	gotoxy(C,L);
    	cout<<P1.pages[L][C]; // Desplay the current letter;
    	i++;// count letters
    	C++; // next position in the array;
    	}
    cout<<endl;
    
    for(int O=0;O<i;O++)//for loop to redispay!
       {
       if(CC==80||P1.pages[LL][CC]==(char)13) {cout<<endl;CC=1;LL++;}
       cout<<P1.pages[LL][CC];
       CC++;
    
       }
    
    }
    
    
    int Save(struct page X)
    {
    	int CC=1,LL=1;
    	cout<<"Enter File name To save: ";
    	cin>>FLN;
    	ifstream outptfile(FLN);
    	if (outptfile.fail())
    	{
    	cout<<"Error Opening the file "<<FLN;
    	return -1;
    	}
    
    	for(int M=0;M<i;M++)
    	 {
     if( (CC==80)||(X.pages[LL][CC]==(char)13) ) //PROBLEM{outptfile<<"\n";CC=1;LL++;}
    	 outptfile.write(X.pages[LL][CC],1); PROBLEM
    	 CC++;
    	 }
        return 0;
       }
    please tell me what wrong.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    43

    Unhappy

    nobody wants to answer!!

    thanks.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    people aren't going to treat that second post of yours very well

    anyway, I would probably pass a pointer to that struct or pass it by reference for one. But that's probably not your problem as doing it the way you are should copy the data. Since I'm too lazy to copy your code over and build it right now, what exactly is the "PROBLEM". You have the comment there but you don't say what happens.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    43
    I'm sorry for the secund post, I had to sayUP) instead.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    43
    Thank you Salem.
    but teach me please what will happen if I begin my array from position 1 and not 0 ? that mean if I read it from 1 and write it from 1 ignoring the pos 0?
    ---
    the problem happen when I pass the P1 to function, then if I put
    X.pages[LL][CC]// it tells me that incorrect operation on struct although I did the same in main() function?
    ----------
    thank you for catching my wrongs.

  6. #6
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    you'll overstep the bounds of the array by 1
    PHP and XML
    Let's talk about SAX

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux and text editor choices
    By pobri19 in forum Linux Programming
    Replies: 9
    Last Post: 06-20-2008, 06:59 AM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. dtextp: a codeforming text editor
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-18-2007, 07:11 AM
  4. make text appear as an asterix
    By Victor4015 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2005, 10:03 AM
  5. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM