Here is my code what I have tried,
I have to take a string from the user and as output i have to print the characters at even places and at odd places separated by a space
MY PROBLEM: In every test case i am assigning to both the strings at end a null character to conclude that my string has ended. Lets suppose i enter 2 test cases and now if enter a smaller string than first test case in result it is printing my character of 2nd test case but also printing the characters of test case because first string was larger than second
I want to ask how it can be possible if i have ended the string with a null character in every test case?
so why it is printing the value after the null character because that were the characters of previous test case because that string was larger and its character are still there in array but it should print till null character Please help me to achieve this.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int t,i,j,k;
scanf("%d ",&t);
while(t>0){
char s[10000],s1[10000],s2[100000];
scanf("%s",s);
for( i=0,j=0,k=0;i<strlen(s);i++){
if(i%2==0)
s1[j++]=s[i];
else
s2[k++]=s[i];
}
s1[strlen(s1)]='\0';
s2[strlen(s2)]='\0';
printf("%s %s\n",s1,s2);
t--;
}
}