Jump to content

Help creating a Text Editor in C

79wjd

@Nineshadow Just a friendly reminder in case you forgot.

 

//if you're busy/lazy then feel free to ignore this

I've been busy today. Just now I've got home to use my computer.

 

I'm trying to implement my own version out of curiosity. Let's see how it turns out.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

@djdwosk97

I'm not too familiar with C (haven't used it too much) , but I made it your text editor in C++ :

#include <iostream>#include <fstream>#include <string>#include <vector>using namespace std;fstream file;vector<string> v(0);void help(){    cout<<"This is a text editor written in C++.\nYou can open it with the command : editor.exe <file_to_open>./nUsage : \np - Print everything in the file.\np <line_nr> - Print everything in the file found at line nr <line_nr>.\nw <line_nr> <string_to_write> - write <string_to_write> at line nr <line_nr>.\n";}void print(){    for(vector<string>::iterator it = v.begin(); it!=v.end(); it++)cout << *it << '\n';}void printl(int line){    if(line < v.size())        cout << v[line]<<'\n';    else cout << "Line not found.\n";}int main(int argc, char *argv[]){    switch(argc)    {    case 1 :        help();        break;    case 2:    {        file.open(argv[1], ios::in | ios::out);        string str;        while(getline(file,str))v.push_back(str);        str.clear();        file.close();        bool running = 1;        while(running)        {            getline(cin,str);            if(str[0]=='p' && str.length() < 2) print();            else if(str[0]=='p')            {                int line = (int)str[2]-48;                printl(line);            }            else if(str[0]=='w' && str.length() > 4)            {                int line = (int)str[2]-48;                string s = str.substr(4);                v[line] = s;            }            else if(str[0]=='s')            {                ofstream out(argv[1]);                for(vector<string>::iterator it = v.begin(); it!=v.end(); it++)out << *it << '\n';                out.close();            }            else if(str[0]=='q')            {                running = 0;                return 0;            }            else help();        }    }    break;    default :        return 0;    }}

Now, time to see what's wrong with your implementation.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

@djdwosk97

I'm not too familiar with C (haven't used it too much) , but I made it your text editor in C++ :

-snip-

Now, time to see what's wrong with your implementation.

God I hate vectors... never really understood that shit. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

God I hate vectors... never really understood that shit. 

Vectors are basically resizable arrays.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Vectors are basically resizable arrays.

yea....I know, but I've never been great with vectors. 

/I miss java arrays :( 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

yea....I know, but I've never been great with vectors. 

/I miss java arrays :(

Pointers ftw.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

@Nineshadow So I wasn't able to figure it out, but I'm still curious to know why it wasn't working (even though I'm already passed the deadline, and have another code due tonight that I'm also having some trouble with :unsure: ) 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

@Nineshadow So I wasn't able to figure it out, but I'm still curious to know why it wasn't working (even though I'm already passed the deadline, and have another code due tonight that I'm also having some trouble with :unsure: ) 

Ah, sorry. School has just started today and I forgot about your problem.

On another note, does the implementation I made in C++ work the way it's supposed to?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Ok, got it up and running (getting no more compiler errors).

Commands don't really work for me.

Printing crashes my program.

Saving doesn't do anything.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Ok, got it up and running (getting no more compiler errors).

Commands don't really work for me.

Printing crashes my program.

Saving doesn't do anything.

Yep, that's where I'm stuck at :P 

 

And I didn't get a chance to try your c++ version out as I've been swamped with work (but still doing a good job of keeping myself distracted :unsure:)

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×