1. read one of the. C file, delete all the comment statements in the file. Then write to the new. C file.
Requirements:
1. Delete Comment statement function using dynamic link library form
2. On the basis of functional realization:
--unit testing should be sufficient
--To pass all the Misra C's checks
--code to conform to code specification.
Analysis:
Read the file (read the entire file size is limited to 100M, if it is greater than this value, do not process, error)
|
|
Analysis file ()
|
|
Working with files
|
|
Write a file
Unit tests:
Normal input, boundary input, illegal input
#include <stdio.h>
int main ()
{
FILE *FP;
Char Buf[100000],ch,flag2;
int i,flag1=0;
if ((Fp=fopen ("hello.c", "R")) ==null)
{
printf ("Can ' t open file");
Exit (1);
}
BUF[0]=FGETC (FP);
I=1;
while ((CH=FGETC (FP))!=eof)
{
Buf[i]=ch;
if (buf[i-1]== '/' &&ch== ' * ')
{
Flag1=1;
i--;
}
if (flag2== ' * ' &&ch== '/')
{
flag1=0;
i--;
}
if (buf[i-1]== '/' &&ch== '/')
{
Flag1=1; -
i--;
}
if (flag2== '/' &&ch== ' n ')
{
flag1=0;
i--;
}
Flag2=buf[i];
if (flag1==0)
i++;
}
buf[i]= ' + ';
Fclose (FP);
if ((Fp=fopen ("New.c", "W")) ==null)
{
printf ("Can ' t open file");
Exit (1);
}
Fputs (BUF,FP);
Fclose (FP);
return 0;
}
Delete a comment