forked from sdsubhajitdas/Compiler-Design-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.c
44 lines (38 loc) · 931 Bytes
/
2.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
44
#include <stdio.h>
#include <string.h>
void substring(char[], char[], int, int);
int main()
{
char str[500];
char token[50];
int idx, i = 0;
printf("Enter a string:\n");
scanf("%[^\n]%*c", str); // string input with spaces.
for (idx = 0; str[idx] != '\0'; idx++)
{
// Tokenizing at space and semicolon.
if (str[idx] == ' ' || str[idx] == ';')
{
substring(str, token, i, idx);
printf("%s \n", token);
i = idx + 1;
}
}
}
void substring(char string[], char sub[], int start, int end)
{
/* Substring function.
string - Actual String from which substring will be made.
sub - Substring created will be stored here.
start - Starting index.
end - Ending index + 1.
*/
int idx = 0;
while (start < end)
{
sub[idx] = string[start];
idx++;
start++;
}
sub[idx] = '\0';
}