Write a program that will read a string from the keyboard and display it after removing all spaces and punctuation characters. All operations should use pointers.
#include<stdio.h>
int main()
{
char s[100];
int i,j;
printf("Enter a sentence: ");
gets(s);
for(i=0; i<strlen(s); i++)
{
if(s[i]==' ' || s[i]=='.' || s[i]==',' || s[i]==':' || s[i]==';' || s[i]=='?' || s[i]=='('||
s[i]==')'|| s[i]=='['|| s[i]==']'|| s[i]=='"')
{
for(j=i; j<strlen(s)+1; j++)
{
s[j]=s[j+1];
}
}
}
for(i=0; i<strlen(s); i++)
{
if(s[i]==' ' || s[i]=='.' || s[i]==',' || s[i]==':' || s[i]==';' || s[i]=='?' || s[i]=='('||
s[i]==')'|| s[i]=='['|| s[i]==']'|| s[i]=='"')
{
for(j=i; j<strlen(s)+1; j++)
{
s[j]=s[j+1];
}
}
}
printf("\nsol:\n%s",s);
}
0 comments:
Post a Comment