Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char *str_func(char *str, char ch, int num)
  5. {
  6.     int i, j = 0, size=0,count=0,temp=num;
  7.     char* new_str = (char *)malloc(sizeof(str) * sizeof(char));
  8.     for (i = 0; str != '\0'; i++)
  9.     {
  10.         if (num >= 0)
  11.         {
  12.             if (str[i] != ch)
  13.             {
  14.                 new_str[j++] = str[i];
  15.                 new_str = (char*)(new_str, ++size * sizeof(char));
  16.             }
  17.         }
  18.         count++;
  19.     }
  20.     if (temp <= count)
  21.     {
  22.         str[size - 1] = '\0';
  23.         strcat(new_str, (str + temp));
  24.     }
  25.     else
  26.         return NULL;
  27.     return new_str;
  28.  
  29. }
  30.  
  31. void main()
  32. {
  33.     char str[] = "heoolloo my noame is bob";
  34.     char *str1;
  35.     str1 = str_func(str, 'o', 30);
  36.     printf("%s\n", str1);
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement