Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.m
- // Exercise V
- //
- // Created by Steve on 11/8/12.
- // Copyright (c) 2012 Personal. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- char * removeExtraSpaces(char * s) {
- char * retval = malloc(strlen(s) + 1);
- char * out = retval;
- int isSpaces = 0; // Indicates whether we're currently copying/reducing a series of one or more spaces.
- while (*s) {
- if (*s != ' ' || !isSpaces) {
- isSpaces = (*s == ' ');
- *out++ = *s;
- }
- s++;
- }
- *out = 0;
- return retval;
- }
- int main(int argc, const char * argv[])
- {
- char * testString = "This has a bunch of spaces.";
- printf("%s\n", testString);
- printf("%s\n", removeExtraSpaces(testString));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement