Write a program that reads a text TXT (less than 200 characters) and removes all occurrences of the 'e' character by packing the remaining items. The changes will be made in the same TXT variable.
Example
This line contains some letters e.
This lin contains som lttrs .
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
void main()
{
/* Declarations */
char TXT[201]; /* given string */
int I,J; /* counters */
/* Reading */
printf("Enter a line (max.200 caracters) :\n");
gets(TXT);
/* Eliminate 'e' letter and pack : */
/* Copy caracters from I to J and incrrment J */
/* only for caracters different than 'e'. */
for (J=0,I=0 ; TXT[I] ; I++)
{
TXT[J] = TXT[I];
if (TXT[I] != 'e')
J++;
}
/* Terminate the string !! */
TXT[J]='\0';
/* Printing the result */
puts(TXT);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Half the input value