-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.c
83 lines (78 loc) · 1.44 KB
/
read.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Group 28
Utkarsh Kumar 2017B2A71008P
Suchisattam Saran 2017B2A70585P
Supratik Bhattacharya 2017B2A70745P
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"def.h"
grammar getPoint(grammar G)
{
G = (grammar)malloc(sizeof(data)*57);
return G;
}
grammar readGrammar(FILE *fp, grammar G)
{
if(fp == NULL){
printf("unable to open the file\n");
exit(1);
}
int i =0;
while(!feof(fp))
{
if(feof(fp)) break;
char c[250];
fscanf(fp, "%[^\n]", c);
//printf("%s\n", c);
char *token;
token = strtok(c, " ");
int flag = 0;
data *nextptr;
while(token != NULL)
{
if(strcmp("->", token) == 0)
{
token = strtok(NULL, " ");
continue;
}
if(flag == 0)
{
strcpy(G[i].symbol, token);
G[i].next = NULL;
//printf("helo %s\n", G[i].symbol);
flag++;
}
else if(flag == 1)
{
data *temp2 = (data *)malloc(sizeof(data));
strcpy(temp2->symbol, token);
temp2->next = NULL;
G[i].next = temp2;
flag++;
nextptr = G[i].next;
//printf("..%s..", nextptr->symbol);
}
else
{
data *temp3 = (data *)malloc(sizeof(data));
strcpy(temp3->symbol,token);
temp3->next = NULL;
nextptr->next = temp3;
nextptr = nextptr->next;
//printf("..%s..", nextptr->symbol);
}
token = strtok(NULL, " ");
}
//printf("\n");
i++;
x =i;
char t = fgetc(fp);
if(t == EOF) break;
if(feof(fp))break;
}
//printf("here Done\n");
fclose(fp);
return G;
}