Thread: A not considered as vowel

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    2

    A not considered as vowel

    Hi all,
    I'm running a program that replaces all the vowels of a given sentence to another given vowel. The issue is that it works for all the vowels except when it has to replace the vowel "A".

    The program is
    Code:
    #include<stdio.h>
    int main(void){
    	char sentence[200], vowel[6]="aeiou", changeVowel;
    	int i, j;
    	printf("Introduce a sentence (max 200 characters)\n");
    	scanf("%[^\n]s", sentence);
    	printf("Introduce a vowel\n");
    	scanf("%s", &changeVowel);
    	for(i=0; sentence[i]!='\0'; i++){
    		for(j=0; j<6; j++){
    			if(sentence[i]==vowel[j]){
    				sentence[i]=changeVowel;
    			}
    		
    		}
    		
    	}
    	printf("%s\n", sentence);
    	return 0;
    }

    As you can see,the A is not switched:
    A not considered as vowel-captura-png

    Do you know what is going on?

    Thanks!

    Sergi

  2. #2
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Code:
     scanf(" %c", &changeVowel);
    try that and be sure you put that space in there too.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Uppercase 'A' is different than lowercase 'a'. In order to account for both, you need to use the standard function tolower(), that converts all uppercase into lowercase letters.
    tolower - C++ Reference
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    2
    That works.
    Thank you so much!!

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    956
    The %s format specifier expects a string, but changeVowel is a single char:

    Code:
    scanf("%s", &changeVowel);
    That seems to overwrite the first character in the vowel string with a null terminator.

    Use " %c" (with the leading space) for the format specifier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deleting vowel words C programming
    By Ignas Kalnietis in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2016, 10:27 AM
  2. Repeat vowel Problem?
    By Khwarizm in forum C Programming
    Replies: 6
    Last Post: 06-09-2014, 12:52 PM
  3. Is it considered rude...
    By SlyMaelstrom in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 11-17-2005, 11:42 AM
  4. Is this considered an AND operation?
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 07-22-2002, 02:40 PM

Tags for this Thread