-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenization
34 lines (30 loc) · 1.04 KB
/
tokenization
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
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100];
char newString[10][10];
int i,j,temp;
printf("\nUniversity of petroleum and energy studies.:\n");
printf("\n");
printf(" Input a string for which you want to perform Tockenization : ");
fgets(str1, sizeof str1, stdin);
j=0; temp=0;
for(i=0;i<=(strlen(str1));i++)
if(str1[i]==' '||str1[i]=='\0')
//if space or NULL found, assign NULL into newString[temp]
{
newString[temp][j]='\0';
temp++; //for next word
j=0; //for next word, init index to 0
}
else
{
newString[temp][j]=str1[i];
j++;
}
printf ("\n tokens after split by space are :\n");
for(i=0;i < temp;i++)
printf(" %s\n",newString[i]);
return 0;
}