//This is the program but printing str1[j] always gives strange output.
//Instead of printing the 15 characters in a sliding pattern in the first instance it concatenates all 5 strings in the first output, 4 in the second and so on.
My objective is to take a string and copy first 10 characters in one string, then next 10 in the next and so on.
If there are any error in the code please correct it.
Thanks in advance
Sucheta
#include<stdio.h>
#include<string.h>
main()
{
char str[20],str1[5][15];
int i,j,k;
scanf("%s",str);
for(i=5,j=0;i>0;i--,j++)
strncpy(str1[j],(str+5-i),15);
for(j=0;j<5;j++)
printf("%s\n",str1[j]);
}



LinkBack URL
About LinkBacks


