String-Array?

I am very new to C programming. Can I make an array of strings so I can display data, line-by-line, pausing between each page? The only alternative is forcing the user to scroll up in the console if they wish to view previous pages of data.

I want my code to look somewhat like this:

1
2
3
4
5
6
7
8
9
for (currentpage=0; currentpage>maxlines/20; currentpage++)
{
    for (currentline=page*20; currentline>page*20+20; currentline++)
    {
        cout<<datastring[currentline]<<"\n"
    }
    cout<<"Enter 1 for next page\n"
    cin>>next
}
You can do (almost) anything with software.

But you don't need nested loops to do it.

pseudo-code:

1
2
3
4
5
6
7
8
9
10
11
linesOutput = 0;
for( lineNumber = 1; lineNumber <= totalLines; ++lineNumber ) {
    cout << line[ lineNumber ] << endl;
    ++linesOutput;
    if( linesOutput == NumberOfLinesPerPage ) {
        cout << "Press ENTER to continue" << endl;
        string temp;
        getline( cin, temp );
        linesOutput = 0;
    }
}

Thanks for the alternative to nested loops, but that doesn't answer my question.

I wanted to know how to declare and store the text data so I can recall it line-by-line in the simplest way possible.
If you want to use arrays, then

1
2
3
4
5
6
7
std::string dataArray[ NUM_LINES ];
size_t       actualNumLines = 0;

// Add to array
assert( actualNumLines < NUM_LINES );
dataArray[ actualNumLines ] = "Hello World";
++actualNumLines;


Preferable would be to use an STL container instead of array. Probably deque is best for your application

1
2
3
4
std::deque<std::string> dataArray;

// Add line
dataArray.push_back( "Hello World!" );

Thanks a lot! Deques will work perfectly for what I want to do.
Topic archived. No new replies allowed.