prev


Character Arrays - String manipulations:

94.Display Nth Line(16.05.2010)

/*
Program# 94
date : 10-01-2009
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++]);
}

}



next
blog comments powered by Disqus