prev


Character Arrays - String manipulations:

95.Display from Nth line to Mth Line(16.05.2010)

/*
Program# 95
date : 10-01-2009
Display from nth to m-th line
*/

#include <stdio.h>
main(){
char a[100];
int i,j=0,n,m;
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 starting line no:");
scanf("%d",&n);

printf("\n Enter ending line no:");
scanf("%d",&m);

i=pos[n-1];
j=pos[m];
while(i



next
blog comments powered by Disqus