Guest User

Untitled

a guest
Jun 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. static int *strip(char *string) {
  6.  
  7. char *buffer = malloc(strlen(string)+1);
  8.  
  9. size_t j = 0;
  10.  
  11. for (size_t c = 0; string[c] != '\0'; c++) {
  12.  
  13. if (string[c] != ' ') {
  14. buffer[j++] = string[c];
  15. }
  16.  
  17.  
  18.  
  19. }
  20.  
  21. buffer[j] = '\0';
  22. return buffer;
  23.  
  24.  
  25. }
  26.  
  27. int main() {
  28.  
  29. char x[] = "h e l l o";
  30.  
  31. char *val = strip(x);
  32.  
  33. printf("%s", val);
  34.  
  35. free(val);
  36.  
  37. return 0;
  38.  
  39. }
  40.  
  41. /* Error :
  42. $ gcc main.c
  43. main.c: In function 'strip':
  44. main.c:22:9: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
  45. return buffer;
  46. ^~~~~~
  47. main.c: In function 'main':
  48. main.c:31:14: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  49. char *val = strip(x);
  50. ^~~~~
  51. */
Advertisement
Add Comment
Please, Sign In to add comment