To begin, you should include the <stdio.h> and <cstring> , since you are using functions declared in these headers, such as the strspn function.
This cycle
for (int i = 0; i < 2; i++) gets_s(s1);
does not make sense. And besides, it uses an incorrect C function, which by the way is not supported by the C ++ standard, gets_s . This function has two parameters, as seen from its declaration.
char *gets_s(char *s, rsize_t n);
you call this function with one argument. Therefore, starting from this point, your program has undefined behavior.
If this function with one parameter is declared as an extension of the language in some compiler, then it is better not to rely on it, since your code in this case will not be portable and will not conform to the C ++ standard.
You should not have this cycle. You should read the line in the next loop. And use standard C ++ functions, such as std::getline , instead of the gets_s function.
This cycle
for (int j = 0; j < sizeof(s1); j++)
also incorrect, since the read string may be shorter than the length of the array s1 . Instead of the value of sizeof( s1 ) you should at least use the value returned by the strlen function. Better yet, just focus on the terminating null of the line, as a condition for loop termination.
In this sentence
if (k == 2) puts(s1);
You are trying to print a string that contains at least one two-digit number, although you must skip such strings by the condition of the assignment.
When using standard C functions such as strspn and strcspn , the program may look like this
#include <iostream> #include <cstring> int main() { const size_t N = 256; char s[N]; const char *digits = "0123456789"; while ( std::cin.getline( s, sizeof( s ) ) && s[0] != '\0' ) { const char *p = s; size_t n = 0; do { n = std::strcspn( p, digits ); p += n; n = std::strspn( p, digits ); p += n; } while ( *p && n != 2 ); if ( n != 2 ) std::cout << s << std::endl; } return 0; }