Skip to content

Commit

Permalink
1.0优化节省存储
Browse files Browse the repository at this point in the history
  • Loading branch information
YujiaCheng1996 committed Oct 12, 2015
1 parent 8b1e484 commit 3763b7b
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions 1.0/1.0/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#define MAXLINELENGTH 200
typedef struct Line
{
int lineNumber;
char lineContent[200];
char content[200];
struct Line * next;
}Line;
main()
Expand Down Expand Up @@ -60,8 +59,7 @@ loop:;// Let user to input the file path.
{
str[strlen(str) - 1] = '\0';
}
strcpy_s(p->lineContent, MAXLINELENGTH, str);
p->lineNumber = fileLineNumber;
strcpy_s(p->content, MAXLINELENGTH, str);
p->next = (Line *)malloc(sizeof(Line));
p = p->next;
}
Expand All @@ -71,7 +69,7 @@ loop:;// Let user to input the file path.
printf("Please comform the content of the file.\n");
for (i = 0; i < fileLineNumber; i++)
{
printf("%4d %s\n", p->lineNumber, p->lineContent);
printf("%4d %s\n", i+1, p->content);
p = p->next;
}
//Let user conform the file(will reload if users does not press y ).
Expand Down Expand Up @@ -109,65 +107,65 @@ loop:;// Let user to input the file path.
p = lp;
for (i = 0; i < fileLineNumber; i++)
{
lineLength = strlen(p->lineContent);
lineLength = strlen(p->content);
for (j = 0; j < lineLength; j++)
{
if (multilineCommentsFlag)
{
if (p->lineContent[j] == '*' && p->lineContent[j + 1] == '/')
if (p->content[j] == '*' && p->content[j + 1] == '/')
{
if (multilineCommentsLineFlag == p->lineNumber)
if (multilineCommentsLineFlag == i+1)
{
for (k = j + 2, t = multilineCommentsFlag - 1; k < lineLength + 1; k++)
{
p->lineContent[t++] = p->lineContent[k];
p->content[t++] = p->content[k];
}
j = multilineCommentsFlag - 1;
}
else
{
for (k = j + 2, t = 0; k < lineLength + 1; k++)
{
p->lineContent[t++] = p->lineContent[k];
p->content[t++] = p->content[k];
}
}
multilineCommentsFlag = 0;
}
if (p->lineContent[j + 1] == '\0')
if (p->content[j + 1] == '\0')
{
if (multilineCommentsLineFlag == p->lineNumber)
if (multilineCommentsLineFlag == i+1)
{
p->lineContent[multilineCommentsFlag - 1] = '\0';
p->content[multilineCommentsFlag - 1] = '\0';
}
else
{
p->lineContent[0] = '\0';
p->content[0] = '\0';
}
}
}
else if (p->lineContent[j] == '/')
else if (p->content[j] == '/')
{
if (p->lineContent[j + 1] == '/')
if (p->content[j + 1] == '/')
{
p->lineContent[j] = '\0';
p->content[j] = '\0';
break;
}
else if (p->lineContent[j + 1] == '*')
else if (p->content[j + 1] == '*')
{
multilineCommentsFlag = j + 1;
multilineCommentsLineFlag = p->lineNumber;
multilineCommentsLineFlag = i + 1;
}
}
}
printf("%4d %s\n", p->lineNumber, p->lineContent);
printf("%4d %s\n", i+1 , p->content);
p = p->next;
}
}
//Check the grammar mistakes.
p = lp;
for (i = 0; i < fileLineNumber; i++)
{
strcpy_s(str, MAXLINELENGTH, p->lineContent);
strcpy_s(str, MAXLINELENGTH, p->content);
lineLength = strlen(str);
parenthesisCount = squareBracketCount = angleBracketCount = singleQuotationMarkCount = doubleQuotationMarkCount = 0;
for (j = 0; j < lineLength; j++)
Expand Down

0 comments on commit 3763b7b

Please sign in to comment.