ポインタを使って逆順にいくつかの単語を出力する必要があります。逆順に単語を印刷できません
たとえば、「Hello World」と指定すると、出力は「World Hello」になります。
これは私がこれまでにやっていることですが、それは何も印刷されません。
void swap(char *ar){
int tmp1[10], tmp2[10], j = 0, k = 0, a, b, z,i; // must use pointers
for (i=0; i<MAX; i++)
{
if(ar[i] == ' ') //if there's a space, store the characters before the space to another array and after the space to another
{
for(j = 0; j<i; j++) // tmp1
tmp1[j] = ar[j];
for(j = 0; j<MAX-i; j++) //MAX - i would be range of j
for(k = i+1; k<MAX; k++) //tmp2
tmp2[j] = ar[k];
}
}
i = 0;
while(1)
{
while(tmp2[i] != '\0' && i<sizeof(tmp2)) // finding the size of tmp2
a++;
}
for(j=0; j<a; j++) // overwriting the original array
ar[j] = tmp2[j];
j++; // incrementing j so that there would be a space between the new array
z = j;
i=0;
while(1) //finding the size of tmp1
{
while(tmp1[i] != '\0' && i<sizeof(tmp1))
b++;
}
//idk pls help
for(z=0 ; z<MAX; z++) //overwriting the original array
for(k = 0; k<b; k++)
ar[z] = tmp1[k];
//idk pls help
for (i = 0; i < MAX; i++) // outputting the required result
printf("%c", *(ar+i));
printf("\n");
}//eg if input is Hello World the output should be World Hello//idk pls help
主な機能はword1
私はあなたの問題があると思いchar word1[] = {'h','e', etc)
あなたが直面している問題は何ですか? – Dalton
あなたの問題は 'while(1)'ループ... "無限ループ"だと思います。 – Dalton
何も印刷されていません –