Answers for "delete char of string in c"

C
2

delete string function in c

/*The logic behind the function is to copy and place the ending part of string
along with the deliminator '\0' to the position from where you want the 
"no_of_char" number of characters removed*/

void delchar(char *string,int starting_pos, int no_of_char)
{
  if (( starting_pos + no_of_char - 1 ) <= strlen(x) )
  {
    strcpy(&x[starting_pos-1],&x[starting_pos + no_of_char-1]);
    puts(x);
    }
}
Posted by: Guest on June-21-2020
0

remove char from string

/* C Program to Remove All Occurrences of a Character in a String */
 
#include <stdio.h>
#include <string.h>
 
int main()
{
  	char str[100], ch;
  	int i, len, j;
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	
  	printf("\n Please Enter the Character that you want to Remove :  ");
  	scanf("%c", &ch);
  	
	len = strlen(str);
	   	
  	for(i = 0; i < len; i++)
	{
		if(str[i] == ch)
		{
			for(j = i; j < len; j++)
			{
				str[j] = str[j + 1];
			}
			len--;
			i--;	
		} 
	}	
	printf("\n The Final String after Removing All Occurrences of '%c' = %s ", ch, str);
	
  	return 0;
}
Posted by: Guest on February-25-2022

Code answers related to "C"

Browse Popular Code Answers by Language