forked from g8bpq/linbpq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatHTML.cpp
60 lines (44 loc) · 1011 Bytes
/
FormatHTML.cpp
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
// FormatHTML.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
int main () {
FILE *fp, *fp2;
char str[256];
char newstr[256];
char * ptr, * inptr;
/* opening file for reading */
fp = fopen("D:/AtomProject/test.html" , "r");
fp2 = fopen("D:/AtomProject/test.html.c" , "w");
if(fp == NULL) {
perror("Error opening file");
return(-1);
}
while(fgets (str, 256, fp) != NULL)
{
// Replace any " with \" and add " on front and \r\n" on end
char c;
ptr = newstr;
inptr = str;
c = *(inptr++);
*(ptr++) = '"';
while (c && c != 10)
{
if (c == '"')
*(ptr++) = '\\';
*(ptr++) = c;
c = *(inptr++);
}
*(ptr++) = '\\';
*(ptr++) = 'r';
*(ptr++) = '\\';
*(ptr++) = 'n';
*(ptr++) = '"';
*(ptr++) = 10;
*(ptr++) = 0;
puts(newstr);
fputs(newstr, fp2);
}
fclose(fp);
fclose(fp2);
return(0);
}