Anyways, I've hit a major programming dilemma. I've been working on a program that involves deleting a specified character from a string. For instance, if I were to type a string called "berry" and I wanted to remove the letter 'e', the program should then display "brry". The program specifications call for the process to be done in a function. However, due to my troubles, I've relegated the issue to main() until I am able to come up with decent output. Furthermore, for strings that take into account multiple instances of a similar letter, only the first instance of the letter is to be deleted.
Here is my code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char input[100],
output[100],
letter;
int char_count,
let_pos;
printf("\nEnter a string: ");
gets(input);
printf("\nEnter letter to delete: ");
letter = getchar();
for (char_count = 0; char_count < strlen(input); char_count++)
{
if (letter == input[char_count])
{
let_pos = char_count;
break;
}
}
for (char_count = 0; char_count < strlen(input); char_count++)
{
if (char_count == let_pos)
;
else
strcpy(&output[char_count], &input[char_count]);
}
printf("%s", output);
return 0;
}
While I can easily pinpoint the character or first instance of multiple characters to be deleted, the actual deletion process is iffy to me. I was considering using the null character to help in the deletion but it would remove all the following characters after the character in 'let_pos'. I've been going around in circles trying to find a coherent solution to the problem but to no avail. Any help would be appreciated. Thanks. 















