plz spot the error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*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");}
   else
   break;
   }break;
}
}
//extraction code
i=start-1;
while(i<=(start-1+num-1))
{
printf("%c",c[i]);
i++;
}
getch();

}
Last edited on
 
Last edited on
thanks @atrium still it doesnt work after ur suggestions....
 
Last edited on
well it just asks for the string and terminates abruptly... am using borland 5.5
 
Last edited on
i enter the string and then it stalls.... it doesnt reach line 13 or 17
If you've made the changes atrium suggested, it should run ok. When I run it with these 2 changes, I get the following output:

Enter the string: hello
5Enter the number of characters to be extracted: 2
Enter the starting point: 3
ll

Andy

PS You might need to add code to handle case strings of length 1?
Last edited on
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......
Topic archived. No new replies allowed.