[問題] 字串倒轉 - 只倒轉母音

作者: 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