-
Notifications
You must be signed in to change notification settings - Fork 0
/
jic.c
43 lines (40 loc) · 1 KB
/
jic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Module to tokenize an array of strings based on an array of delimiters.
* Author: Simon Haile
* Date: May 22, 2017
*/
//#include "tokenizer.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int tokenize(char *line, char *delimiters);
int main(int argc, char *argv[]){
char delimiters[2] = {'-', '!'};
tokenize("hello-word!", delimiters);
}
/*
* Loop through the line, until the null character, to determine size
* of array to return.
*/
int tokenize(char *line, char *delimiters){
int arrSize=0;
while(*line != '\0'){
printf(":%c\n",*line );
//while i havent found a token counterr, keep going.
//add one to arrSize
//while i havent found a delimiter, keep going.
if((strchr(delimiters, *line)) || (*line == '\0')){
line++;
if( ((!(strchr(delimiters, *line))) && (*line != '\n')) ){
line--;
arrSize++;
printf("%d\n",arrSize );
}
else{
line--;
}
}
++line;
}
return arrSize;
}