#include<stdio.h>
#include<malloc.h>
#include<string.h>
int main()
{
int n,i,length,j;
char **ptrarray;
scanf("%d",&n);
ptrarray = malloc(n*sizeof(*ptrarray));
for (i=0;i<n;i++)
ptrarray[i] = (char *)malloc(200);
for (i=0;i<n;i++)
fgets(ptrarray[i],200,stdin);
for (i=0;i<n;i++)
{
length=strlen(ptrarray[i])-1;
for (j=0;j<(length)/2;j+=2)
{
printf("%c",ptrarray[i][j]);
}
printf("\n");
}
return 0;
}
This gives me the correct answer when I run it on codeblocks using GCC but on ideone and while submitting, I get wrong answer instead!
On ideone, my output only gives -
y
po
i
Instead of the expected output -
y
po
i
ntc
However the printf loop is supposed to run 4 times. What could be causing this error?