Alright, so I've got a linked list program going here, and I've succesfully loaded a text file, and I fed each line from the text file into my linked list nodes.

Now I want to create a few commands that's going to allow me to alter this text file, while it's in my linked list.

If the letter I is entered with a number n following it, then insert the text to be followed before line n. If I is not followed by a number, then insert the text before the current line. If D is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command L, which stands for listing lines. Entry E signifies exit and saving the text in a file.

If you need to see any part of my current code, just let me know...

I was thinking, I wrote a fraction calculator last year that took the fraction (12/25 for example) and it did a search in the string for the '/' and took the first half, put that into a variable, and took the second half and put that into a variable. Just dismissed the slash of course, would it theoretically be possible to do the same here?

probably the easiest solution is to do a switch statement on the letter entered and then process the number(s) following it inside the case. Might want to write separate functions for each case to make the switch statement smaller and more manageable.

What do you think the best way to process the numbers following it? Using a size_t and doing a .find?

if the command is in a std::string, just look at each character. Its not really all that difficult to do, so don't make it more complicated than it really is.

std::string command = "I1";

...
switch(command[0])
{
    case 'I':
    {
          int lineno = -1; // default is current line
          if( command.length() > 1 && isdigit(command[1]))
               lineno = command[1] - '0'; // make line number binary
          // rest of code here
     }

An altered version of that might work, but where I'm going to need different kinds of inputs, ex. If a user wants to alter a certain line, they hit "I 3" to alter line 3, "I 5" to alter line 5 and so forth. I don't know if case() can handle something like that, I ended up doing this:

if (exec == "I") //[0] == 'I' && exec[1] == ' ')
                    {
                        bool lineEdit = true;
                        while(lineEdit)
                        {
                            cout << "This mode will allow you to keep adding lines onto the end of the file.\n"
                                << "When you are finished, simply type '1' to return to the main menu.";
                            cout << "> ";
                            getline(cin,doWork);

                            if (doWork == "1")
                            {
                                lineEdit = false;
                            }
                            else
                            {
                                list.Add( new fileNode(doWork));
                                list.Dump();
                            }
                        }
                    }
                    else if (exec[0] == 'I' && isdigit(exec[2]))
                    {
                        cout << "It is numeric I!";
                    }

if the command is in a std::string, just look at each character. Its not really all that difficult to do, so don't make it more complicated than it really is.

std::string command = "I1";

...
switch(command[0])
{
    case 'I':
    {
          int lineno = -1; // default is current line
          if( command.length() > 1 && isdigit(command[1]))
               lineno = command[1] - '0'; // make line number binary
          // rest of code here
     }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.