H
Hello
i'm trying to make a program to take out non alpha characters from
entered text...but 'ntext' is always 4 char larger than the size
j...why is that?
any better ways to do this? thanks lots people.
void main()
{
int i, j=0;
char text[9999];
char *ntext;
gets(text);
for (i=0; text; i++){
if(isalpha(text))
j++;
}
ntext=new char [j];
cout<<j<<" "<<strlen(ntext);
for (i=0, j=0; text;i++){
if (isalpha(text)){
ntext[j]=text;
j++;
}
}
strcpy(text, ntext);
cout<<endl;
for (i=0; text; i++)
cout<<endl<<text;
delete [] ntext;
}
entered text...but 'ntext' is always 4 char larger than the size
j...why is that?
any better ways to do this? thanks lots people.
void main()
{
int i, j=0;
char text[9999];
char *ntext;
gets(text);
for (i=0; text; i++){
if(isalpha(text))
j++;
}
ntext=new char [j];
cout<<j<<" "<<strlen(ntext);
for (i=0, j=0; text;i++){
if (isalpha(text)){
ntext[j]=text;
j++;
}
}
strcpy(text, ntext);
cout<<endl;
for (i=0; text; i++)
cout<<endl<<text;
delete [] ntext;
}