c string not printing

Jan 23, 2020 at 8:37am
closed account (1bfSwA7f)
hello,
I was wondering why my c string from my array was not printing?

code:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void sentenceCapitalizer(char *ptr);

int main(){

const int MAX_SENTENCE_LENGTH = 200;
char userString[MAX_SENTENCE_LENGTH] = " no, not tonight. it's a very popular place \
and you have to make reservations in advance. besides, \
it's expensive, and I don't have any money.";

cin.getline(userString, MAX_SENTENCE_LENGTH);

cout << "The text before the modification: \n" << userString << '\n';

return 0;

}


output:

The text before the modification:
Last edited on Jan 23, 2020 at 8:38am
Jan 23, 2020 at 8:46am
@osheik, please use code tags.

Your program DOES print:
1234
The text before the modification:
1234



Jan 23, 2020 at 8:46am
> cin.getline(userString, MAX_SENTENCE_LENGTH);
So delete this line then, or make getline use a different char array.
Jan 24, 2020 at 12:57am
closed account (1bfSwA7f)
tttt
Last edited on Jan 25, 2020 at 6:36am
Topic archived. No new replies allowed.