Delete a comment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.