[问题] 字串倒转 - 只倒转元音

楼主: EngRookie (EngRookie)   2016-05-11 14:42:02
大家好,小弟又来打扰各位,小弟有两个问题如下:
1. 在不新增副函式的引数 char *returnStr 是否有其他办法 return 字串回去?
2. 我的 malloc 是建立在副函式里面并且在最后 return 回去,我该如何 free(pointer)呢?
程式码如下:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool isVowels(char *s)
{
if (s >='A'&& s <='Z')
s += 'a' - 'A';
return s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u';
}
char* reverseVowels(char* s, char *returnStr)
{
int L = 0, R = strlen(s) - 1;
char tempChar = '0';
char *Array = (char *)malloc(strlen(s)*sizeof(char));
for (int i = 0; i < strlen(s); i++)
Array[i] = *(s + i);
while (L < R)
{
while (!isVowels(Array[L]))
L++;
while (!isVowels(Array[R]))
R
作者: KJFC (磁铁猫)   2016-05-11 15:00:00
reference?

Links booklink

Contact Us: admin [ a t ] ucptt.com