samedi 4 avril 2015

c++ Array MEMMOVE bug

So, what I want to do is placing a 'p' before all vowels, I'm doing that but because of the memmove, the char array is filled with strange symbols.



#include<conio.h>
#include <cstring>

#include <iostream>
using namespace std;

int main()
{
char s1[256];
cin.get(s1,255);
cin.get();
for(int i=0;i<strlen(s1);i++)
{
if(strchr("aeiou",s1[i])){
memmove(s1+i+1,s1+i,strlen(s1));
// duplicating the vowel so i can replace it
s1[i]='p';
i++;
}
}
cout<<s1;
getch();
return 0;
}

Aucun commentaire:

Enregistrer un commentaire