Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line. 0 will be considered as even index. Number of input strings can be T from 1 to 10. The program is giving correct results in codeblocks (offline) but not on HackerRank platform. Its giving the error:
solution.cc: In function 'int main()':
solution.cc:22:9: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] gets(g[i].s); ^
solution.cc:22:20: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] gets(g[i].s); ^
/ccQXNkYE.o: In function
main': solution.cc:(.text.startup+0x4e): warning: thegets' function is dangerous and should not be used.
My code is:
#include <cstdio>
#include <iostream>
struct str {
    char s[10000];
};
int main() {
    using namespace std;
    int T; 
    cin >> T;
    fflush(stdin);
    str g[10];
    for(int i = 0; i < T; ++i) {
        gets(g[i].s);
        fflush(stdin);
    }
    for(int t = 0; t < T; ++t) {
        int j = 0;
        while(j < strlen(g[t].s)) {
            if(j % 2 == 0)
                cout << g[t].s[j];
            ++j;
        }
        cout << " ";
        int k = 0;
        while(k < strlen(g[t].s)) {
            if(k % 2 == 1)
                cout << g[t].s[k];
            ++k;
        }
        cout << endl;
    }
    return 0;
}
 
     
     
    