LED PANEL

Google It, You'll Get It.

Monday, January 31, 2011

Scan and delete a desired a word from a sentence



#include

main()
{
int i=0;
int length = 0;
int word = 1;
int remove=0;
int tempw=1;

//read the string
char strng[50];
printf("enter the string : ");
gets(strng);
printf("Saved String : ");
puts(strng);
//printf("Initial values : Length %d, word %d, wotd numb %d, i %d. \n",length, word, wn, i);

//calculate the length
while(strng[i]!='\0')
{
length++;
i++;
}
printf("String Length : %d \n",length);

// calculate the no of words
i=0;
word=1;
while(i {
if(strng[i]==' ')
word++;
i++;
}
printf("nO. of Words : %d \n",word);

//askng for the word to delete
printf("Enter the word number you need to delete : ",word);
scanf("%d",&remove);

//scaning for that word
for(i=0;i { if(strng[i]==' ')
tempw++; // 2nd word count
if(tempw==remove)
printf("%c",strng[i]);
}
}

1 comment:

  1. nice work. so after removing the word, how do you print the resulting string? for example the string I AM A BOY. if i remove the second which is AM, then the resulting string should be I A BOY....

    ReplyDelete