/*Program to extract m characters from string starting from the nth character */
#include<conio.h>
#include<stdio.h>
main()
{
char *c;
int i=0,j=0,count=0,num,start;//it is better to use more variables than to reuse one variable to avoiid confusion
printf("Enter the string ");
scanf("%s",c);
//count the number of characters in the string
while(c[count]!='\0')
{count++;
} printf("%d",count);
//wrong input check code ie it rules out impossible combination of inputs and asks the user to reenter it
while(1)
{
printf("enter the number of characters to be extracted ");
scanf("%d",&num);
if(num>=count)
{printf("impossible dude try reentering");}
else
{
while(2)
{
printf("enter the starting point");
scanf("%d",start);
if((count-start)>num)
{printf("impossible dude try reentering");}
elsebreak;
}break;
}
}
//extraction code
i=start-1;
while(i<=(start-1+num-1))
{
printf("%c",c[i]);
i++;
}
getch();
}
thanks andy and atrium alot..... i got confused as without allocating space for the character array c it worked on my desktop but not on my laptop; meaning if u do not allocate space then it MAY or MAY NOT work.......once again thanks a ton......