Advertisement
Guest User

no_space.c

a guest
Apr 8th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. int no_space_strlen(const char *s) {
  4.  
  5.   int len, j;
  6.  
  7.   len = j = 0;
  8.   while (s[len] != '\0') {
  9.     if (s[len] == ' ')
  10.       j++;
  11.     len++;
  12.   }
  13.   return (len - j);
  14. }
  15.  
  16. char *no_space(const char *str_in) {
  17.  
  18.   char *space_free;
  19.   int i, j;
  20.   i = j = 0;
  21.   space_free = (char *)malloc(sizeof(char) * no_space_strlen(str_in) + 1);
  22.   while(str_in[i] != '\0' && space_free != NULL) {
  23.     if(str_in[i] != ' ') {
  24.       space_free[j] = str_in[i];
  25.       j++;
  26.     }
  27.     i++;
  28.   }
  29.   space_free[j] = '\0';
  30.   return (space_free);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement