Saturday, 14 September 2013

C PROGRAM TO DELETE AN ELEMENT IN THE ARRY -C STRING PROGRAMS

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

int main()
{
    char str[81];
    unsigned int length=0; //to store string length
    unsigned int pos=0; //posotion of the element to be deleted


    printf("enter your string:");
    gets(str);
    length=strlen(str);

    printf("\nenter the position of the  element you want to delete:");
    scanf("%ud",&pos);
    pos=pos-1;   //user thinks first element of the array as 1

    if(pos<0)
    {
        printf("specified element position cnnot be located in the string\n");
        getch();
        exit(1);
    }

    strcpy(&str[pos],&str[pos+1]);
    printf("\n");
    puts(str);
}

No comments:

Post a Comment