[ create a new paste ] login | about

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

C, pasted on Aug 17:
#include<iostream.h>

char *strtok_new(char * string, char const * delimiter){
   static char *source = NULL;
   char *p, *riturn = 0;
   if(string != NULL)         source = string;
   if(source == NULL)         return NULL;

   if((p = strpbrk (source, delimiter)) != NULL) {
      *p  = 0;
      riturn = source;
      source = ++p;
   }
return riturn;
}

int main(){
   char string[] = "one,,three,";
   char delimiter[] = ",";
   char * p    = strtok_new(string, delimiter);

   while(p){
            if(*p)  cout << p << endl;
            else    cout << "No data" << endl;                
            p = strtok_new(NULL, delimiter);
   }
   system("pause");
   return 0;
}


Output:
1
2
3
4
5
6
7
8
Line 20: error: iostream.h: No such file or directory
In function 'strtok_new':
Line 9: warning: incompatible implicit declaration of built-in function 'strpbrk'
In function 'main':
Line 23: error: 'cout' undeclared (first use in this function)
Line 23: error: (Each undeclared identifier is reported only once
Line 23: error: for each function it appears in.)
Line 23: error: 'endl' undeclared (first use in this function)


Create a new paste based on this one


Comments: