Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- static int *strip(char *string) {
- char *buffer = malloc(strlen(string)+1);
- size_t j = 0;
- for (size_t c = 0; string[c] != '\0'; c++) {
- if (string[c] != ' ') {
- buffer[j++] = string[c];
- }
- }
- buffer[j] = '\0';
- return buffer;
- }
- int main() {
- char x[] = "h e l l o";
- char *val = strip(x);
- printf("%s", val);
- free(val);
- return 0;
- }
- /* Error :
- $ gcc main.c
- main.c: In function 'strip':
- main.c:22:9: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
- return buffer;
- ^~~~~~
- main.c: In function 'main':
- main.c:31:14: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
- char *val = strip(x);
- ^~~~~
- */
Advertisement
Add Comment
Please, Sign In to add comment