Problem Description
Write a function that accepts a string using pointers. In the function ,delete all the occurrences of a given character and display the modified string on the screen
Input and Output Format:
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.Test Case 1
Input (stdin)SRM University S
Expected OutputRM University
Test Case 2
Input (stdin)SRM University R
Expected OutputSM University
Program
#include <stdio.h> #include<string.h> int main() { char str[15],ch,cat[10]; scanf("%s%s",str,cat); scanf("%s",&ch); int i=0,j,len; 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("%s ",str); printf("%s",cat); return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.