[ create a new paste ] login | about

Link: http://codepad.org/vSs4pNK5    [ raw code | output | fork ]

C, pasted on May 12:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void squeeze(char *s, int s_size, char *e, int e_size)
{
  int i, j, gap = 0;

  // itterate over all characters in the string
  for (i = 0; i < s_size; i++)
  {
    // for each character, compare it against
    // all characters in the exclusion string.
    for (j = 0; j < e_size; j++)
    {
      // if the current char of the string
      // matches the current char of the exclusion
      // list then we widen the gap set and goto
      // the end of the upper loop.
      if (s[i] == e[j])
      {
	gap++;
	goto skip_char;
      }
    }

    // if this section of code is being executed it means
    // that the current charecter was not in the exclusion list
    // so we throw it over the gap and keep it.

    s[i - gap] = s[i];

    skip_char:
    continue;
  }

  // chop off chars dangling off the edge
  s[s_size - gap] = '\0';
}

int main(int argc, char **argv)
{
  char str[] = "this is a super awesome string";
  int s_len = 30;
  char exc[] = "aeiou";
  int e_len = 5;

  printf("String before: %s\n", str);
  squeeze(str, s_len, exc, e_len);
  printf("String after: %s\n", str);

  return 0;
}


Output:
1
2
String before: this is a super awesome string
String after: ths s  spr wsm strng


Create a new paste based on this one


Comments: