All pastes #362460 Raw Edit

Untitled

public c v1 · immutable
·published 2007-02-18 20:59 UTC
rendered paste body
jdp@localhost ~/src/src $ cat string.c//malloc()#include <stdlib.h>#include <stdio.h>#include "string.h"//memcpy()#include <string.h>// tc = token count//      assumes token seperator to be ASCII 32(" ")int tc(char s[]){ int x = strlen(s), a, i=0; for(a=0; a<=x; ++a) {  if (s[a] == 32) ++i; }return i+1;}// token get//// assumes token seperator to be ASCII 32(" ") and returns n tokenint *tg(char s[], int n){ int x = strlen(s), a, i=0, l=0; s[x] = 32; ++x; for (a=0;a<=x;++a) {  if (s[a] == 32)  {   //++i;   if (n==++i)   {    return ss(s,l,a-1);   }else{    l = a+1;   }  }//if space }// for return 0;}// substring//// string, start, endint *ss(char s[], int a, int b){ return memcpy(malloc(b-a), &s[a], (b-a)+1);}