There is such a code. I need something to break the line into words, but it stops on the first space.

SetConsoleCP(1251); SetConsoleOutputCP(1251); int n,n2; char str[80], str3[80]; scanf("%s", str); str3[0] = '\0'; char * pch = strtok(str, ",\n"); while( pch != NULL) { cout << pch << endl; pch = strtok(NULL, ",\n"); } system("pause"); return 0; 

    1 answer 1

    The scanf function stops reading when a white space character is encountered. Use at least fgets instead. For example,

     fgtes( str, sizeof( str ), stdin ); 

    This function can add a newline character to the end of a character array.

    Better yet, use standard C ++ streaming functions. For example,

     std::cin.getline( str, sizeof( str ) );