Sample input:
hello world
a b c d
Sample output:
hello
a
world
b
c
d
Im stuck in a infinite while loop(while(j<maxStr+2)) and i need help to get out of it.Please help! Here is my code:
#include "stdafx.h"
#include <string.h>
#define MAX_STR 5
int _tmain(int argc, _TCHAR* argv[])
{
int i=0,j=0,strNum,maxStr=0,len=0;
int progress[MAX_STR]={0};
char str[MAX_STR][50]={0};
printf("Number of sentences you want to enter(1-5):");
while(scanf("%d",&strNum)<1 || strNum>MAX_STR||strNum==0||strNum<0){
printf("Invalid input!Plese enter again:");
fflush(stdin);
}
for(i=0; i < strNum ; i++){
printf("\nEnter sentence #%d: ",i+1);
scanf(" %[^\n]s",str[i]);
}
for(i = 0; i < strNum; i++) {
len = strlen(str[i]);
if(maxStr < len ){
maxStr=len;
}
}
while(j<maxStr+2){
for(i=0;i<strNum;i++){
j=progress[i];
if(str[i][j]!=' '&&str[i][j]!='\0'){
while(str[i][j]!=' '&&str[i][j]!='\0')
{
printf("%c",str[i][j]);
j++;
}
printf("\n");
progress[i]=j+1;
}
}
}
return 0;
}