-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
694 lines (633 loc) · 29.2 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include "expressions2.c"
#define constant 256
int main (int argc,char *argv[]) {
FILE *fp;
FILE *out;
FILE *outfunc;
char line[256];
// array to store splitted line
char *splittedLines[256];
for (int i = 0; i < 256; i++) splittedLines[i] = calloc(256, sizeof(char*));
char *varNames[512];
for (int i = 0; i < 512; i++) varNames[i] = calloc(256, sizeof(char));
char *varTypes[512];
for (int i = 0; i < 512; i++) varTypes[i] = calloc(256, sizeof(char));
char *row_dimensions[512];
for (int i = 0; i < 512; i++) row_dimensions[i] = calloc(256, sizeof(char*));
char *col_dimensions[512];
for (int i = 0; i < 512; i++) col_dimensions[i] = calloc(256, sizeof(char*));
char *resultArr[256];
for (int i = 0; i < 256; i++) resultArr[i] = calloc(256, sizeof(char*));
char *vectorArr[256];
for (int i = 0; i < 256; i++) vectorArr[i] = calloc(256, sizeof(char*));
int varNumber = 0;
int vectorNum = 0;
bool * err = false;
/* Open file for reading Filename is given on the command line */
if (argc != 2) {
printf("Give filename as command line argument\n") ;
return(1);
}
fp = fopen(argv[1], "r");
// detects file cannot open error
if(fp == NULL) {
printf("Cannot open %s\n",argv[1]);
return(1);
}
//reserved tokens
char tokens[12] = {'[' , ']' , ',' , '(' , ')' , '=', ':', '{', '}', '*', '+', '-'};
int reserved[12];
for(int i = 0; i < 12; i++){
int temp = (int) tokens[i];
reserved[i] = temp;
}
char space = ' ';
int lineId = 0;
//reads input from file
while( fgets(line,256,fp) != NULL ) {
int tokenId = 0;
int j = 0;
char newSentence[512];
int lineLength = strlen(&line[0]);
char printline[256];
printline[0] = '\0';
for(int i = 0; i < strlen(&line[0]); i++){
//checks tokens if its reserved or alphanumeric
if(line[i] == '#'){
break;
}
if(isReserved(line[i], reserved)) {
newSentence[j] = space;
j++;
newSentence[j] = line[i];
j++;
newSentence[j] = space;
j++;
}else if (isalnum(line[i]) || (int) line[i] == (int)space){
newSentence[j] = line[i];
j++;
}
}
//printf("%s\n", newSentence);
// splits the tokens that includes space between them
char *token = strtok(newSentence, " ");
while( token != NULL ) {
//stores each token in array
memcpy(splittedLines[tokenId], token, 256);
tokenId += 1;
token = strtok(NULL, " ");
}
memcpy(splittedLines[tokenId],"exit",256);
lineId += 1;
//checks 0 index and choose what to do
if(strcmp(splittedLines[0],"matrix")==0 ){
//matrix declaration
if(strcmp(splittedLines[2],"[")==0 && strcmp(splittedLines[6],"]")==0&& isInteger(splittedLines[3])&& isInteger(splittedLines[5])&&\
strcmp(splittedLines[4],",")==0){
memcpy(varTypes[varNumber], splittedLines[0], 100);
if(isValidName(splittedLines[1])){
memcpy(varNames[varNumber], splittedLines[1], 100);
memcpy(row_dimensions[varNumber], splittedLines[3], 100);
memcpy(col_dimensions[varNumber], splittedLines[5], 100);
}else{
error(lineId);
*err = true;
break;
}
//print to c file
strcat(printline, "double **") ;
strcat(printline, varNames[varNumber]) ;
strcat(printline, " = malloc(sizeof(double*)*") ;
int entryNum = atoi(row_dimensions[varNumber])*atoi(col_dimensions[varNumber]);
char entryNumber[50];
sprintf(entryNumber, "%d", entryNum);
strcat(printline, entryNumber) ;
strcat(printline, " );for(int i = 0; i < ") ;
strcat(printline, entryNumber) ;
strcat(printline, " ; i++){") ;
strcat(printline, varNames[varNumber]) ;
strcat(printline, "[i] = malloc(sizeof(double)*") ;
strcat(printline, entryNumber) ;
strcat(printline, ");}") ;
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 256);
varNumber++;
}else{
error(lineId);
*err = true;
break;
}
//statements for declarations
}else if(strcmp(splittedLines[0],"vector")==0){
//if first token is equal to vector
memcpy(vectorArr[vectorNum],splittedLines[1],24);
vectorNum++;
if(strcmp(splittedLines[2],"[")==0 && strcmp(splittedLines[4],"]")==0 && isInteger(splittedLines[3])){
memcpy(varTypes[varNumber], "matrix", 100);
if(isValidName(splittedLines[1])){
memcpy(varNames[varNumber], splittedLines[1], 100);
memcpy(row_dimensions[varNumber], splittedLines[3], 100);
}else{
error(lineId);
*err = true;
break;
}
char col = '1';
memcpy(col_dimensions[varNumber], &col, 100);
// printing to c file
strcat(printline, "double **") ;
strcat(printline, varNames[varNumber]) ;
strcat(printline, " = malloc(sizeof(double*)*") ;
strcat(printline, row_dimensions[varNumber]) ;
strcat(printline, " );for(int i = 0; i < ") ;
strcat(printline, row_dimensions[varNumber]) ;
strcat(printline, " ; i++){") ;
strcat(printline, varNames[varNumber]) ;
strcat(printline, "[i] = malloc(sizeof(double)*") ;
strcat(printline, row_dimensions[varNumber]) ;
strcat(printline, ");}") ;
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 256);
varNumber++;
}else{
error(lineId);
*err = true;
break;
}
}else if(strcmp(splittedLines[0],"scalar")==0){
//scalar declaration
memcpy(varTypes[varNumber], splittedLines[0], 100);
//checks if varname is valid
if(isValidName(splittedLines[1])){
memcpy(varNames[varNumber], splittedLines[1], 100);
}else{
error(lineId);
*err = true;
break;
}
row_dimensions[varNumber] = NULL;
col_dimensions[varNumber] = NULL;
// printing to c file
strcat(printline, "double ") ;
strcat(printline, splittedLines[1]) ;
strcat(printline, "; ") ;
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
varNumber++;
//Statements for assignment statements
}else if(strcmp(splittedLines[1],"=") == 0){
char *as_var_name = calloc(24, sizeof(char));
memcpy(as_var_name, splittedLines[0],8);
//looks if variable is declared
if(isVariable(as_var_name,varNames)){
int as_var_index = find(as_var_name, varNames);
//assignment for matrices
if(strcmp(varTypes[as_var_index],"matrix") == 0 || strcmp(varTypes[as_var_index],"vector") == 0){
int row_num_as_matrix = atoi(row_dimensions[as_var_index]);
int col_num_as_matrix = atoi(col_dimensions[as_var_index]);
// looks for matrix assignment which is done with curly braces
if(strcmp(splittedLines[2],"{") == 0 && strcmp(splittedLines[3+(row_num_as_matrix*col_num_as_matrix)], "}") == 0){
int entry_number = row_num_as_matrix*col_num_as_matrix;
for(int i=0;i<row_num_as_matrix;i++){
for(int j=0;j<col_num_as_matrix;j++){
int entry_char_size = strlen(splittedLines[3+(i*col_num_as_matrix+j)]);
char *entry_value_in_char = calloc(entry_char_size,sizeof(double));
memcpy(entry_value_in_char,splittedLines[3+(i*col_num_as_matrix+j)],entry_char_size);
//print to c file
char str_i[50];
char str_j[50];
sprintf(str_i, "%d", i);
sprintf(str_j, "%d", j);
strcat(printline, as_var_name) ;
strcat(printline, "[") ;
strcat(printline, str_i) ;
strcat(printline, "]") ;
strcat(printline, "[") ;
strcat(printline, str_j) ;
strcat(printline, "]") ;
strcat(printline, "=") ;
strcat(printline, entry_value_in_char) ;
strcat(printline, ";") ;
int len = strlen(printline);
printline[len] = '\0';
}
}
memcpy(resultArr[lineId], printline, 100);
}else if(true){
//Matrix can assigned by expression assign matrix here
char *expr1[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
for(int i = 2; i <256; i++){
if (strcmp(splittedLines[i], "exit")==0){
memcpy(expr1[i-2], splittedLines[i],10);
break;
}
expr1[i-2] = splittedLines[i];
}
char result[256];
char *result2[256];
for (int i = 0; i < 256; i++) result2[i] = calloc(256, sizeof(char*));
int tmpId = 0;
expr( result , expr1, varNames,lineId,err);
char *tmp = strtok(result, " ");
while( tmp != NULL ) {
//stores each token in array
memcpy(result2[tmpId], tmp, 256);
tmpId += 1;
tmp = strtok(NULL, " ");
}
memcpy(result2[tmpId], "exit", 10);
char result3[256];
result3[0] = '\0';
int* pvarNum;
pvarNum = &varNumber;
postFixToInfix(result2, result3, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
int index = find(result3,varNames);
if(strcmp(varTypes[index],"matrix") != 0 ){
error(lineId);
*err = true;
break;
}
//print to c file
strcat(printline, as_var_name) ;
strcat(printline, "=") ;
strcat(printline, result3);
strcat(printline, ";");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
memset(result3,0,256);
}
else{
error(lineId);
*err = true;
//where are my curly braces or there are not right number of entries for variable matrix
//break;
}
//assignments of scalar type variables
}else if(strcmp(varTypes[as_var_index],"scalar") == 0 ){
char *expr1[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
for(int i = 2; i <256; i++){
if (strcmp(splittedLines[i], "exit")==0){
memcpy(expr1[i-2], splittedLines[i],10);
break;
}
expr1[i-2] = splittedLines[i];
}
char result[256];
char *result2[256];
for (int i = 0; i < 256; i++) result2[i] = calloc(256, sizeof(char*));
int tmpId = 0;
expr( result , expr1, varNames, lineId,err);
char *tmp = strtok(result, " ");
while( tmp != NULL ) {
//stores each token in array
memcpy(result2[tmpId], tmp, 256);
tmpId += 1;
tmp = strtok(NULL, " ");
}
memcpy(result2[tmpId], "exit", 10);
char result3[256];
result3[0] = '\0';
int* pvarNum;
pvarNum = &varNumber;
//returns the expression the left
postFixToInfix(result2, result3, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
int index = find(result3,varNames);
if(index != -1){
if(strcmp(varTypes[index],"scalar") != 0 && !isNumber(result3)){
error(lineId);
*err = true;
break;
}
}
//print to c file
strcat(printline, as_var_name) ;
strcat(printline, "=") ;
strcat(printline, result3);
strcat(printline, ";");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
memset(result3,0,256);
}
}
else{
error(lineId);
*err = true;
//there is no such variable declared to assign
break;
}
// statements of for loops if first token is equal to for
}else if(strcmp(splittedLines[0],"for") == 0){
//single for loop with one loop variable
if(strcmp(splittedLines[3],"in") == 0 && strcmp(splittedLines[1],"(") == 0){
varNames[varNumber] = splittedLines[2];
varNumber++;
//for loop expressions
char *expr1[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
char *expr2[256];
for (int i = 0; i < 256; i++) expr2[i] = calloc(256, sizeof(char*));
char *expr3[256];
for (int i = 0; i < 256; i++) expr3[i] = calloc(256, sizeof(char*));
int cur = 4;
int temp = cur;
char postexpr1[256];
char postexpr2[256];
char postexpr3[256];
postexpr1[0] = '\0';
postexpr2[0] = '\0';
postexpr3[0] = '\0';
for (int i = 4; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], ":")==0){
break;
}
memcpy(expr1[i-4],splittedLines[i],10);
}
memcpy(expr1[cur-temp-1], "exit", 10);
temp = cur;
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], ":")==0){
break;
}
memcpy(expr2[i-temp],splittedLines[i],10);
}
memcpy(expr2[cur-temp-1], "exit", 10);
temp = cur;
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], ")")==0){
break;
}
memcpy(expr3[i-temp],splittedLines[i],10);
}
memcpy(expr3[cur-temp-1], "exit", 10);
if(!strcmp(splittedLines[cur-1], ")")==0){
error(lineId);
*err = true;
break;
}
char * arr[4] = {"22", "+", "3", "exit"};
//converts expressions into the postfix notation
expr( postexpr1 , expr1, varNames, lineId,err);
expr( postexpr2 , expr2, varNames, lineId,err);
expr( postexpr3 , expr3, varNames, lineId,err);
int* pvarNum;
pvarNum = &varNumber;
char *postArr1[256];
for (int i = 0; i < 256; i++) postArr1[i] = calloc(256, sizeof(char*));
char *postArr2[256];
for (int i = 0; i < 256; i++) postArr2[i] = calloc(256, sizeof(char*));
char *postArr3[256];
for (int i = 0; i < 256; i++) postArr3[i] = calloc(256, sizeof(char*));
char *tmp = strtok(postexpr1, " ");
int tmpId = 0;
while( tmp != NULL ) {
//stores each token in array
memcpy(postArr1[tmpId], tmp, 256);
tmpId += 1;
tmp = strtok(NULL, " ");
}
memcpy(postArr1[tmpId], "exit", 100);
tmpId = 0;
char *tmp2 = strtok(postexpr2, " ");
while( tmp2 != NULL ) {
//stores each token in array
memcpy(postArr2[tmpId], tmp2, 256);
tmpId += 1;
tmp2 = strtok(NULL, " ");
}
memcpy(postArr2[tmpId], "exit", 100);
tmpId = 0;
char *tmp3 = strtok(postexpr3, " ");
while( tmp3 != NULL ) {
//stores each token in array
memcpy(postArr3[tmpId], tmp3, 256);
tmpId += 1;
tmp3 = strtok(NULL, " ");
}
memcpy(postArr3[tmpId], "exit", 100);
tmpId = 0;
char res1[256];
res1[0] = '\0';
char res2[256];
res2[0] = '\0';
char res3[256];
res3[0] = '\0';
// convertion of postfix forms into the infix form for assignments in the file.c
postFixToInfix(postArr1, res1, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
postFixToInfix(postArr2, res2, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
postFixToInfix(postArr3, res3, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
//print to c file
strcat(printline, "for( int ");
strcat(printline, splittedLines[2]);
strcat(printline, " = ");
strcat(printline, res1);
strcat(printline, ";");
strcat(printline, splittedLines[2]);
strcat(printline, " < ");
strcat(printline, res2);
strcat(printline, ";");
strcat(printline, splittedLines[2]);
strcat(printline, " = ");
strcat(printline, splittedLines[2]);
strcat(printline, "+");
strcat(printline, res3);
strcat(printline, ") {");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
//nested for
}else if(strcmp(splittedLines[3],",") == 0 && strcmp(splittedLines[1],"(") == 0 && strcmp(splittedLines[5],"in") == 0){
char *expr1[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
char *expr2[256];
for (int i = 0; i < 256; i++) expr2[i] = calloc(256, sizeof(char*));
char *expr3[256];
for (int i = 0; i < 256; i++) expr3[i] = calloc(256, sizeof(char*));
char *expr4[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
char *expr5[256];
for (int i = 0; i < 256; i++) expr2[i] = calloc(256, sizeof(char*));
char *expr6[256];
for (int i = 0; i < 256; i++) expr3[i] = calloc(256, sizeof(char*));
int cur = 6;
}else{
error(lineId);
*err = true;
}
//change matrix index (cannot be finished)
/*
}else if(strcmp(splittedLines[1],"[") == 0){
printf("%s \n", splittedLines[0]);
char *expr1[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
char *expr2[256];
for (int i = 0; i < 256; i++) expr2[i] = calloc(256, sizeof(char*));
char *as_var_name = calloc(24, sizeof(char));
int cur = 2;
memcpy(as_var_name, splittedLines[0],8);
int as_var_index = find(as_var_name, varNames);
if(strcmp(varTypes[as_var_index],"matrix") == 0 && !isVector(splittedLines[0],varTypes)){
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], ",")==0 ){
break;
}
expr1[i-2] = splittedLines[i];
}
int temp = cur;
if(strcmp(splittedLines[temp-1],",") == 0){
printf("bu %s", varTypes[as_var_index]);
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], "]")==0){
break;
}
expr2[i-temp] = splittedLines[i];
}
}else{
error(lineId);
break;
}
}else if (isVector(splittedLines[0],varTypes)){
bool check = true;
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], "]")==0 ){
check = false;
break;
}
expr1[i-2] = splittedLines[i];
}
}
*/
//end of for loop
}else if(strcmp(splittedLines[0], "}") == 0){
strcat(printline, "}");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
//print statements with first token is equal to print keyword
}else if(strcmp(splittedLines[0], "print") == 0){
// parenthesis is used to distinguish the expressions
if(strcmp(splittedLines[1], "(") == 0){
//initialization of expression arrays in order to convert them to postfix form
char *expr1[256];
char *result2[256];
for (int i = 0; i < 256; i++) expr1[i] = calloc(256, sizeof(char*));
for (int i = 0; i < 256; i++) result2[i] = calloc(256, sizeof(char*));
char postexpr[256];
postexpr[0] = '\0';
int cur = 2;
int temp = cur;
for (int i = cur; i < 256; i++){
cur++;
if(strcmp(splittedLines[i], ")")==0){
break;
}
memcpy(expr1[i-temp],splittedLines[i],10);
}
memcpy(expr1[cur-temp-1], "exit", 10);
if(!strcmp(splittedLines[cur-1], ")")==0){
error(lineId);
*err = true;
break;
}
expr( postexpr , expr1, varNames, lineId,err);
int tmpId = 0;
char *tmp = strtok(postexpr, " ");
while( tmp != NULL ) {
//stores each token in array
memcpy(result2[tmpId], tmp, 256);
tmpId += 1;
tmp = strtok(NULL, " ");
}
memcpy(result2[tmpId], "exit", 10);
char res1[256];
res1[0] = '\0';
int* pvarNum;
pvarNum = &varNumber;
//convertion of postfix form expression into the infix form for printing in file.c
postFixToInfix(result2, res1, varNames,varTypes, lineId, pvarNum, col_dimensions, row_dimensions, vectorArr);
int index = find(res1,varNames);
char * type = varTypes[index];
// if id is scalar, there is no need for indexing
if(strcmp(type,"scalar")==0){
//print to c file
strcat(printline, "printf(\"%f\", ");
strcat(printline, res1);
strcat(printline, ");");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
// if id is in type of matrix, looks and checks for indexing
}if (strcmp(type,"matrix")==0){
//print to c file
char* colNum = col_dimensions[index];
char* rowNum = row_dimensions[index];
int len1 = strlen(colNum);
colNum[len1] = '\0';
int len2 = strlen(rowNum);
rowNum[len2] = '\0';
strcat(printline, "matrix_printer(");
strcat(printline, res1);
strcat(printline, ",");
strcat(printline, rowNum);
strcat(printline, ",");
strcat(printline, colNum);
strcat(printline, ");");
int len = strlen(printline);
printline[len] = '\0';
memcpy(resultArr[lineId], printline, 100);
}
}else{
error(lineId);
*err = true;
}
}
// empty the array
memset(newSentence,0,512);
}
fclose(fp);
// if there is no error prints the output
if(!err){
out = fopen("./file.c","w");
if(out == NULL)
{
printf("Error!");
exit(1);
}
outfunc = fopen("./outputfunctions.c","r");
if(outfunc == NULL)
{
printf("Error!");
exit(1);
}
fprintf(out,"%s","#include <stdio.h> \n#include <string.h> \n#include <stdlib.h> \n#include <stdbool.h>\n#include <ctype.h> \n#include <math.h>\n");
char funcs[512];
while(fgets(funcs,512,outfunc) != NULL){
fprintf(out,"%s",funcs);
}
fprintf(out, "%s", "int main (int argc,char *argv[]) {\n");
for(int i = 0; i<256; i++){
fprintf(out,"%s",resultArr[i]);
fprintf(out,"%s","\n");
}
fprintf(out, "%s", "}");
fclose(out);
}
return(0);
}