Skip to content

Instantly share code, notes, and snippets.

@mygnu
Last active January 3, 2016 13:09

Revisions

  1. mygnu revised this gist Jan 17, 2014. 1 changed file with 1 addition and 18 deletions.
    19 changes: 1 addition & 18 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -34,21 +34,4 @@ void removeXtraSpaces(char str[], char nstr[])
    }

    }
    {
    flag = SPACE;
    }

    else if (flag == SPACE)
    {
    flag = NONSPACE;
    *nstr = ' ';
    }


    str++;
    nstr++;
    }
    *str = '\0';


    }

  2. mygnu revised this gist Jan 17, 2014. 1 changed file with 24 additions and 20 deletions.
    44 changes: 24 additions & 20 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,9 @@

    #define SPACE 1
    #define NONSPACE 0

    #include "header.h" // all required header files

    void removeXtraSpaces(char str[],char nstr[]);

    int
    main(int argc, char *argv[])
    {
    char mystr[20] = "The brown fox";
    char mystr[50] = {"The brown fox."};
    //gets(mystr);
    char result[20];
    char result[50];// = "______________";
    printf("%s \n", mystr);

    removeXtraSpaces(mystr, result);
    @@ -20,16 +12,28 @@ main(int argc, char *argv[])
    }

    void removeXtraSpaces(char str[], char nstr[])
    {
    int flag = NONSPACE;

    while (*str != '\0')
    {
    if(*str != ' ')
    {
    *nstr = *str;
    }
    else if (*str == ' ')
    {
    int flag = NONSPACE;

    while (*str != '\0')
    {
    if(*str != ' ')
    {
    flag = NONSPACE;
    *nstr = *str;
    nstr++;
    }
    else if (*str == ' ' && flag == NONSPACE)
    {
    flag = SPACE;
    *nstr = ' ';
    nstr++;
    }

    str++;
    }

    }
    {
    flag = SPACE;
    }
  3. mygnu created this gist Jan 17, 2014.
    50 changes: 50 additions & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@

    #define SPACE 1
    #define NONSPACE 0

    #include "header.h" // all required header files

    void removeXtraSpaces(char str[],char nstr[]);

    int
    main(int argc, char *argv[])
    {
    char mystr[20] = "The brown fox";
    //gets(mystr);
    char result[20];
    printf("%s \n", mystr);

    removeXtraSpaces(mystr, result);
    printf("%s\n", result);

    }

    void removeXtraSpaces(char str[], char nstr[])
    {
    int flag = NONSPACE;

    while (*str != '\0')
    {
    if(*str != ' ')
    {
    *nstr = *str;
    }
    else if (*str == ' ')
    {
    flag = SPACE;
    }

    else if (flag == SPACE)
    {
    flag = NONSPACE;
    *nstr = ' ';
    }


    str++;
    nstr++;
    }
    *str = '\0';


    }