Prog#094: Display n-th line

/* 
Program#94
Display n-th line
*/

#include <stdio.h>
main(){
char a[100];
int i,j=0,n;
int pos[100];
i=0;

scanf("%c",&a[i]);
while(a[i]!='$'){
i++;
scanf("%c",&a[i]);
}
a[i]='\0';

i=0;
pos[j++]=0;
while(a[i]!='\0'){
if(a[i]=='\n'){
pos[j++]=i+1;
}
i++;
}
//end array
pos[j]=-1;
j=0;
while(pos[j]!=-1){
printf("\n %d",pos[j++]);
}

//n-th line
printf("\n Enter line no:");
scanf("%d",&n);

i=pos[n-1];
while(a[i]!='\n'){
printf("%c",a[i++]);
}

}