A
A
Alex_Tysel2014-04-27 16:30:15
C++ / C#
Alex_Tysel, 2014-04-27 16:30:15

Problem with strings in c++?

Hello, please help with the solution. At the university, a task was given for laboratory work: Enter a list of the names of students in the group, request a coherent text consisting of several sentences, where previously entered surnames are used. Correct the entered text so that only surnames and the first words in sentences are capitalized.
The only thing with which there are difficulties is how to correct the names in the entered text.
Here is the code:

#include <iostream>
#pragma warning(disable : 4996)
using namespace std;

int main()
{	
  char lastname[1000];
  char text[1000];
  cout << "Enter the last names of all students in your group:" << endl;
  gets(lastname);
  cout << "Enter the text with last names entered earlier:"<<endl;
  gets(text);
  text[0] = toupper(text[0]);
  for (int i = 0; text[i] != '\0'; ++i){
    if (text[i] == '.'){
      text[i+1] = toupper(text[i+1]);
    }
  }
  cout << text << endl;
  system("pause");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pigah, 2014-04-27
@pigah

Split the resulting text into an array of words using the Split function , and to change the letters to uppercase use the toupper function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question