-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrimline.c
54 lines (48 loc) · 1.1 KB
/
trimline.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
/* Austin Hester
CS 4280 sp18
C.Z. Janikow */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "trimline.h"
#include "alphabet.h"
// for tracking multi-
// line comments
static int commentflag = 0;
// trim spaces and comments out
// also symbols not in the alphabet
void
trimline(char* dest, const char* src)
{
int i = 0;
int j = 0;
char buf[256];
char c = src[i];
while (c != '\0')
{
if (c == '&') {
// toggle comment
commentflag = (commentflag + 1) % 2;
if (commentflag == 0) {
// marks end of comment
c = src[++i];
continue;
}
}
if (commentflag || !isinalphabet(c)) {
// forget comments and symbols not in the alphabet
c = src[++i];
continue;
}
if (buf[j-1] == '=' || buf[j-1] == '>' || buf[j-1] == '<') {
if (c != ' ')
buf[j++] = c;
} else {
buf[j++] = c;
}
c = src[++i];
}
buf[j] = '\0';
strcpy(dest, buf);
return;
}