mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
24 lines
405 B
C
24 lines
405 B
C
char *reverseOnlyLetters(char *S)
|
|
{
|
|
int last = strlen(S) - 1, i;
|
|
for (i = 0; i < last;)
|
|
{
|
|
if (!isalpha(S[i]))
|
|
{
|
|
i++;
|
|
continue;
|
|
}
|
|
if (!isalpha(S[last]))
|
|
{
|
|
last--;
|
|
continue;
|
|
}
|
|
char tmp = S[i];
|
|
S[i] = S[last];
|
|
S[last] = tmp;
|
|
i++;
|
|
last--;
|
|
}
|
|
return S;
|
|
}
|