I am an absolute beginner to c++ and for assignment I need to do multiple functions and send the single .cpp file.
My code is:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
char* toTitleCase(const char* text) {
int i;
char a[30];
cin.getline(a, 30);
a[0] = a[0] - 32;
for (i = 0; a[i] != NULL; i++)
{
if (a[i] == ' ')
{
a[i + 1] = a[i + 1] - 32;
}
}
cout << a;
return 0;
}
char* removeSpaces(const char* text) {
char str[100];
int i = 0, len, j;
cout << "Enter a string: ";
gets_s(str);
len = strlen(str);
for (i = 0; i < len; i++) {
if (str[i] == ' ') {
for (j = i; j < len; j++)
str[j] = str[j + 1];
len--;
}
}
cout << "Result string: " << str;
return 0;
}
int main() {
cout << removeSpaces("hello. this is a test");
cout << toTitleCase("hello. this is a test");
char str[100];
//cout << "Result string: " << removeSpaces(str);
return 0;
}
The problem is that, it only works for the first called function but not the second, and it just exits the code. Please, any reason why or what would I be supposed to do?