Ejemplo n.º 1
0
char* CVcardView::StrTrim(char *cs)
{
    char* ret = cs;
    char* pc = new char[strlen(cs) + 1];
	
    int pos = strspn(cs, "\t \n");      // 查找非空白处pos
    strcpy(pc, cs + pos);
    StringReverse(pc); // 反序字符串
    pos = strspn(pc, "\t \n");  // 原来后面的空白,就变成了前面的空白
    strcpy(cs, pc + pos);
    StringReverse(cs);  // 再反序,还原回来
	
    delete[] pc;
    return ret;
}
// make sure the return char array is initialized with \0 null terminators;
int main(int argc, char** argv) {
    char name[] = "Recursion";
    char rev[sizeof(name)] = {0};
    StringReverse(name,rev);
    printf("%s",rev);
    return (EXIT_SUCCESS);
}
Ejemplo n.º 3
0
Bool StringGetNWords_LeN_Back(/* RESULTS */ char *output, /* INPUT */ char *in,
                              char *in_base, int maxlen, int n,
                              /* RESULTS */ char **nextp)
{
  char	*orig_out, buf[PHRASELEN], *out;
  int	inword;
  out = buf;
  orig_out = out;
  inword = 0;
  maxlen--;
  while (*in && in >= in_base) {
    if (LexEntryNonwhite(*((uc *)in))) {
      if (!inword) {
        inword = 1;
        n--;
        if (orig_out != out) {
          if ((out - orig_out) >= maxlen) {
            return(0);
          }
          *out = SPACE;
          out++;
        }
      }
      if ((out - orig_out) >= maxlen) {
        return(0);
      }
      *out = *in;
      out++;
      in--;
    } else {
      if (n == 0) {
        *nextp = in-1;	/* todo? */
        *out = TERM;
        StringReverse(orig_out, output);
        return(1);
      }
      inword = 0;
      in--;
    }
  }
  return(0);
}
Ejemplo n.º 4
0
// Converts interger n to characters in s
//
// @param n integer
// @param s string converted from n
void IntegerToString(int n, char s[]) {
  int i = 0;
  // Most left single numeric digit in integer n.
  int remain = 0;
  int sign = n;
  int base = 10;

  if (sign < 0) {
    n = -n;
  }
  do {
    remain = n % base;
    s[i++] = digit[remain];
  } while ((n /= base) != 0);
  if (sign < 0) {
    s[i++] = '-';
  }
  s[i] = '\0';
  StringReverse(s, i);
}
Ejemplo n.º 5
0
int main()
{
	char szStr[MAX_STR_LEN] = {0};	//String to be reversed.
	char* pszRev = NULL;			//Pointer to reversed string

	//Request input
	printf(STRING_REQ);
	gets(szStr);

	//Reverse the string.
	pszRev = StringReverse(szStr);

	//Check return value.
	if(pszRev != NULL)
	{
		printf(PRG_OUTLINE);
		puts(szStr);
		printf(LINE_FEED);
		return TRUE;
	}

	return FALSE;
}
void StringReverse(char* original, char* reversed){
    if(*original){
        StringReverse(original+1,reversed);
        reversed[i++] = *original;
    }
}