top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a program to remove extra spaces and punctuation from a sentence using C?

+2 votes
635 views
Write a program to remove extra spaces and punctuation from a sentence using C?
posted Jan 12, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Are u looking for exact code or algo steps are fine ?
Here, What do u mean by "punctuation"?

1 Answer

0 votes
int main(int argc, char *argv[])
{
   unsigned char indx = 0;

   if (argc != 3)
   {
      printf("Invalid No. of arguments passed");
      return 0;
   }

   char result[255] = {'\0'};
   char *input = argv[1];
   char rmchar = *argv[2];

   while(*input)
   {
      if (*input != rmchar)
      {
         result[indx++] = *input;
      }
      input++;
   }

   printf("%s",result);

   return 0;
}

This code is working and giving expected result.
input - $ ./a.out abcd:abcd:abcd :
output - $abcdabcdabcd
Here punctuation is semicolon :

answer Jan 13, 2016 by Harshita
...