jeudi 14 avril 2022

string problem in C++ . when input is greater than 10 , the problem behaving abnormal [closed]

#include <iostream>


#include <string>

using namespace std ;

int main ( )

{

    int i , j , n , m ;

    string str , str1  ;

    getline (cin , str ) ;

    n = str.length( ) ;

    for (i=0 ; i<n ; i++ )

    {

        if (str[i] >=65 && str[i] <=90) {

            str[i] = str[i] + 32 ;

        }

    }

    for (i=0 , j = 0; i<n   ; i++) {

        if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i]== 'u')
 {

            continue ;

    }

    else {

        str1[j] = '.' ;

        str1[j+1] = str[i] ;

        j= j+ 2 ;

        m = j ;

    }

    }

    for (i=0 ; i < m ; i++) {

        cout << str1[i] ;

   }

    return 0 ;

}

why I found garbage value when input is greater then 11 characters ? if less then 11 , it is behaving perfectly . I basically want to remove all the vowel from the input and put dot before every consonant .

Aucun commentaire:

Enregistrer un commentaire