I'm supposed to make a program that replaces vowels in a string for numbers, without using and using pointers.
I used the commented printf in each switch statement to debug my program, and the output when the string is: aeiou, is:
4eiou
3iou
1ou
0u
2
and at the end when printing the string it just prints a blank line, when the output should be: 43102.
I'm doing something wrong that's replacing the complete string, but I can't figure it out. Can someone help me? Thank you very much!
#include <stdio.h>
void changes(char* ptr) {
while (*ptr != '\0') {
switch(*ptr) {
case 'a':
*(ptr)='4';
//printf("%s\n", ptr);
break;
case 'e':
*(ptr)='3';
//printf("%s\n", ptr);
break;
case 'i':
*(ptr)='1';
//printf("%s\n", ptr);
break;
case 'o':
*(ptr)='0';
//printf("%s\n", ptr);
break;
case 'u':
*(ptr)='2';
//printf("%s\n", ptr);
break;
default:
break;
}
ptr++;
}
//Print the string
printf("%s\n", ptr);
}
int main() {
char sString[51];
char *charPtr = NULL;
charPtr = &sString[0];
printf("Introduce a string: ");
scanf("%[^\n]s", sString);
changes(charPtr);
}