我正在製作提取給定字符串的某些部分的程序。 但它在功能extct()
for循環中有一些問題; for循環沒有終止於a<=b
。它只是通過它並終止於a!='\0'
。for循環不終止在C
int main()
{
void extct();
char my_string[50];
printf("Enter anything: ");
scanf("%[^\n]s",my_string);
extct(my_string);
getch();
return 0;
}
void extct(char *a)
{
int i,j,l;
char new_string[50];
printf("Enter location from you want to extract string: ");
scanf("%d",&i);
printf("Now enter no. of letters you want to extract from previous entered location: ");
scanf("%d",&j);
a=a+(i-1); //sets address to entered location
int b=a+j; //sets limit for the for loop
for(l=0;(a<=b)||(*a!='\0');a++,l++)
{
new_string[l]=*a;
}
new_string[l]='\0';
printf("\n%s",new_string);
}
調試器是使用工具。 –
'true ||假'評估爲'真' –