character vector

0

The exercise asks to, from a vector with a phrase, show its content in gibberish (it has to go through the arrangement, when it finds a vowel, it adds p + vocal example: hidden: e eg sco po ndi pi do po). I did it with a switch, but it's not working for me. Also, I would have to load it into an M x N matrix. The code I made is the following:

#include<stdio.h>

char jerigonza (char frase[], int n){
    //lee frase y la guarda en el arreglo frase
    for (int i=0; i<n;i++){
        printf ("Escriba una frase:\n");
        scanf ("%s", frase);
    }

    //busca vocales y le agrega p+vocal
       for (int j=0; j<n; j++){
            switch (frase[j]){
                case 'A': case 'a': printf ("pa");
                                    break;
                case 'E': case 'e': printf ("pe");
                                    break;
                case 'I': case 'i': printf ("pi");
                                    break;
                case 'O': case 'o': printf ("po");
                                    break;
                case 'U': case 'u': printf ("pu");
                                    break;
                default: return 0;
                        break;
            }
        }
}


int main(){

char a[50];
jerigonza (a,50);

return 0;
}
    
asked by Adri 13.07.2018 в 21:43
source

2 answers

0

Let's see if I can get it:

Since we have a vector of a given size, we have to control that we paint only the number of characters that the phrase that they have given us, because if we paint the whole vector, we are possibly painting garbage. I leave some comments in the code to help you. Greetings.

#include<stdio.h>

char jerigonza (char frase[], int n){
    //lee frase y la guarda en el arreglo frase
    //primero quitamos el for que lo que hacía era pedirte la frase n veces
        printf ("Escriba una frase:\n");
        scanf ("%s", frase);

    //busca vocales y le agrega p+vocal
       for (int j=0; j<n; j++){
            switch (frase[j]){
                //si hay coincidencia añadimos la 'p'
                case 'A': case 'a': printf ("pa");
                                    break;
                case 'E': case 'e': printf ("pe");
                                    break;
                case 'I': case 'i': printf ("pi");
                                    break;
                case 'O': case 'o': printf ("po");
                                    break;
                case 'U': case 'u': printf ("pu");
                                    break;
                //si hemos llegado al final de la cadena, dejamos de pintar
                case '
Escriba una frase:
hola
hpolpa
': return 0; //si no coincide y no es fin de cadena, pintamos la letra tal cual default: printf("%c",frase[j]); break; } } } int main(){ char a[50]; jerigonza (a,50); return 0; }

Output generated:

#include<stdio.h>

char jerigonza (char frase[], int n){
    //lee frase y la guarda en el arreglo frase
    //primero quitamos el for que lo que hacía era pedirte la frase n veces
        printf ("Escriba una frase:\n");
        scanf ("%s", frase);

    //busca vocales y le agrega p+vocal
       for (int j=0; j<n; j++){
            switch (frase[j]){
                //si hay coincidencia añadimos la 'p'
                case 'A': case 'a': printf ("pa");
                                    break;
                case 'E': case 'e': printf ("pe");
                                    break;
                case 'I': case 'i': printf ("pi");
                                    break;
                case 'O': case 'o': printf ("po");
                                    break;
                case 'U': case 'u': printf ("pu");
                                    break;
                //si hemos llegado al final de la cadena, dejamos de pintar
                case '
Escriba una frase:
hola
hpolpa
': return 0; //si no coincide y no es fin de cadena, pintamos la letra tal cual default: printf("%c",frase[j]); break; } } } int main(){ char a[50]; jerigonza (a,50); return 0; }
    
answered by 14.07.2018 / 17:18
source
0

Sorry for the format I am writing the answer from a mobile. The explanation is the following you only have to add the printf to the for so you get the letter and if it is a vowel when it enters the switch it prints the corresponding one if it is a vowel. Another syringe thing that does not return char changes that by void. I hope this solves everything. Remember to mark the answer as correct if it works ok. Salu2

//busca vocales y le agrega p+vocal 
 for (int j=0; j<n; j++)
 { 
      printf(frase[j]); 
      switch (frase[j])
      {
            case 'A': case 'a': printf ("pa"); break;
            case 'E': case 'e': printf ("pe"); break; 
            case 'I': case 'i': printf ("pi"); break; 
            case 'O': case 'o': printf ("po"); break; 
            case 'U': case 'u': printf ("pu"); break; 
            default: break; 
       } 
    }
    
answered by 14.07.2018 в 04:43