-2
我目前正在學習編程,我不知道爲什麼我的代碼沒有進入那是在做的內部。C:沒有輸入「for」聲明內部做...而
任何想法或幫助將非常有幫助!
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
void swap(char *num1, char *num2) {
char temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
int main()
{
int l,i;
char s[100];
bool swapped;
scanf("%s", s);
l=strlen(s);
do
{
swapped = 0;
for(i=1;i==(l-1);i++)
{
if(s[i-1] > s[i])
{
swap(&s[i-1],&s[i]);
printf("%s\n",s);
swapped = 1;
}
}
}while(swapped);
// printf("%s\n",s);
return 0;
}
你開始'I = 1',所以'我==(L-1)'爲真,當且僅如果'l == 2'。也許你的意思是'我<=(l-1)'。 – user3386109
'i ==(l-1)'會檢查'i'是否是'_equat_到'l-1',否則不會進入循環。那是你需要的嗎? – ForceBru
歡迎來到堆棧溢出。您似乎需要學習如何使用調試器逐行執行代碼,這可能使您可以輕鬆查明所遇問題的性質和位置。對於所有的意圖和目的,使用調試器都是任何程序員都需要的知識。有關更多信息,請參閱[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 –