2 years ago

#55915

test-img

Patton13

Remove the lowercase vowels [C]

I'm learning C and I got a task to to remove the lowercase vowels (a, e, i, o, u) in a given string. so I wrote this code and I'm getting Segmentation fault error in line 15, can someone explain me why I'm getting this error, how to avoid getting this error, and how to solve this error?

Thx, appreciated!

#include <stdio.h>

char *shortcut(char *str_out, const char *str_in);

int main()
{
    shortcut("", "how are you today?");
    return 0;
}

char *shortcut (char *str_out, const char *str_in)
{
    for (int i = 0; str_in[i] != 0; i++) {
        if (str_in[i] != 'a' && str_in[i] != 'e' && str_in[i] != 'i' && str_in[i] != 'o' && str_in[i] != 'u')
            *str_out++ = str_in[i];
    }

    *str_out = '\0'; // write to str_out
    return str_out; // return it
}

c

error-handling

computer-science

0 Answers

Your Answer

Accepted video resources