by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to delete character from String using pointer concept. User declares char type array variable. User using malloc() function for the allocate the memory to the variable. Then user asks to enter the string then shifted the ptr to str variable for address reference. Then user puts the while condition to verify condition. In condition while (*ptr! =NULL) then if (*ptr!=ch) is that all the conditions got true the *ptr2 will be *ptr2++ with increment operator. And in the end the given result will be on the screen at the end.

Problem Statement:
This is C program where coder has to use pointer function for the deletion of character from string.

  1. Declare the variables.
  2. Using loop statement and control statements.
  3. Display result in the screen.

Here is C source code for Deleting the Character from the string using pointer function. The output of this program shown below. 

#include<stdio.h>

void main()
{
    char str[100],ch,*ptr,*ptr2;
    clrscr();
    ptr2=(char*)malloc(20);
    printf("Enter a String :");
    gets(str);
    printf("Enter the Character you Want to Delete :");
    scanf("%c",&ch);
    ptr = str;
    while(*ptr!=NULL)
            {
               if(*ptr!=ch)
                 {
                     *ptr2=ch;
                       ptr2++;
                 }
                     ptr++;
            }
                     printf("%s",ptr2);
                     getch();



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.