Remove first character of each word from a string
C program to eliminate/remove first character of each word from a string.
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 50
void main()
{
char str[MAX];
int i, j, k, len;
printf("Enter the string\t:");
gets(str);
len = strlen(str);
if(str[0] != ' ')
{
for(i=0;i<len;i++)
{
str[i] = str[i+1];
}
len--;
}
for(i=0;i<len;i++)
{
if(str[i]==' ' && str[i+1]!=' ')
{
for(j=i+1;j<len;j++)
{
str[j] = str[j+1];
}
len--;
}
}
str[len] = '\0';
printf("\nModified string\t:%s",str);
getch();
}
Output
Enter the string :welcome to coursecrux.com, happy coding!!!
Modified string :elcome o oursecrux.com, appy oding!!!