I need to make a program that asks the user to input a number of strings, and then outputs the string database. The program should maintain a string database where each record is a string. The program keeps reading strings that the user has typed, and inserts the string at a sorted position in the database dynamically. The user presses ctrl+Z to end the process of inputting the strings, and then the program displays the whole string database.
The program only allows the user to input up to 10 strings, and if more are inputted an error message should be displayed.
Basically, the user types a number of sentences, and then the sentences are sorted (by the first letter of that sentence) and then outputted in that new order. So if someone typed:
Hello
How are you today
Are you okay?
the result would be:
Are you okay?
Hello
How are you today
The idea I have for my code is the following:
for the main function (pseudocode):
while (1){
read a string;
if not successful, end the while loop;
else insert the string at a sorted position in the string database;
}
display the string database;
so I am working on a function for the first 'if' statement, called readstring:
char *ReadString(char *a)
{
for (char *b = a; *b; b++)
I believe this for loop scrolls through every character for a string, and I think what I need to do is have one pointer store the first character to one pointer, and then have that pointer store the next character as another pointer, and so on. I am really unclear as exactly how to approach this problem. If anyone can help me with this function/the rest of the problem that would be great, thanks!
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
cout << " String Database" << endl;
cout << " Please type some strings, and the database will sort them" << endl;
cout << " Press ^Z to end the string input" << endl;
while(1)
{
//read the string using ReadString function
//If not successful, break;
//else, insert the string at a sorted position in the database
}
//display the string database
}
//Functions
char *ReadString(char *a)
{
for (char *b = a; *b; b++)