- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,我目前不在考虑以下问题
char*s="HELLO WORLD /*ABCD*/";
#include <stdio.h>
int main()
{
FILE *src=fopen("Program.c","rb");
if(src==0)
{
printf("ERROR OPENING THE SOURCE FILE\n");
return 0;
}
FILE *des=fopen("NewProgram.txt","wb");
if(des==0)
{
printf("ERROR OPENING THE DESTINATION FILE\n");
return 0;
}
char ch;
while((ch=fgetc(src))!=EOF)
{
if(ch=='/')
{
ch=fgetc(src);
if(ch=='/')//single line comment encountered
{
while((ch=fgetc(src))!='\n');//scan till an 'ENTER' is found
fputc(ch,des);//adding the '\n' to the file
}
else if(ch=='*')//multi-line or documentation encountered
while((ch=fgetc(src))!='/');//scan till the closing '/' is encountered
else
{
fputc('/',des);
fputc(ch,des);
}
}
else
fputc(ch,des);
}
return 0;
}
#include <stdio.h>
int nthNonFibonacci(int n,int a,int b);
//call the function with (n(the desired term),fib1,fib2)
//fib1 and fib2 are 2 and 3 respectively
//they are starting consecutive fibonacci numbers
//0 and 1 avoided as they shall unnecessarily increase stack depth
int main()
{
int n;//to store the upper limit
printf("ENTER THE UPPER LIMIT OF NON FIBONACCI SERIES\n");
scanf("%d",&n);//input of upper limit
printf("\nTHE SERIES :\n");
for(int i=1;i<=n;i++)
printf("%d ",nthNonFibonacci(i,2,3));
return 0;
}
/** a and b are two consecutive fibonacci numbers
* (b-a-1) => gives the number of non fibonacci numbers b/w a and b
* we subtract (b-a-1) from n to make sure that we have logically traversed
* the non fibonacci numbers b/w a and b
* this is done when n-(b-a-1)>0 and also at the same time we update a
* and b to the next consecutive fibonacci numbers
* now our base case is when in a pass n-(b-a-1) <=0 which means that
* our required nth non fibonacci number lies b/w current a and b
* so in that situation we simply return the LOWER_LIMIT_FIBONACCI(i.e. a)
* added to current n
*/
int nthNonFibonacci(int n,int a,int b)
{
if((n-(b-a-1))<=0)
return (n+a);
else
return nthNonFibonacci(n-(b-a-1),b,a+b);
}
#include <stdio.h>
int nthNonFibonacci(int n,int a,int b);
int main()
{
int n;
printf("ENTER THE UPPER LIMIT OF NON FIBONACCI SERIES\n");
scanf("%d",&n);
printf("\nTHE SERIES :\n");
for(int i=1;i<=n;i++)
printf("%d ",nthNonFibonacci(i,2,3));
return 0;
}
w a and b
* we subtract (b-a-1) from n to make sure that we have logically traversed
* the non fibonacci numbers b/w a and b
* this is done when n-(b-a-1)>0 and also at the same time we update a
* and b to the next consecutive fibonacci numbers
* now our base case is when in a pass n-(b-a-1) <=0 which means that
* our required nth non fibonacci number lies b/w current a and b
* so in that situation we simply return the LOWER_LIMIT_FIBONACCI(i.e. a)
* added to current n
*/
int nthNonFibonacci(int n,int a,int b)
{
if((n-(b-a-1))<=0)
return (n+a);
else
return nthNonFibonacci(n-(b-a-1),b,a+b);
}
最佳答案
您需要检查* /,而不仅是/,因为您的某些注释本身已经存在,请检查。请注意,您的代码已从/ ** ..... b /中删除了该部分。
下面给出的是实现该问题的代码的修改版本。
#include <stdio.h>
void removeComments();//removes the comments from the file
//pointed by src
FILE *src,*des;//file pointers for the source and destination
int main()
{
src=fopen("Program.c","rb");//opening the source program
//file in read binary mode
if(src==0)//fopen return NULL if there is error in opening
{ //file
printf("ERROR OPENING THE SOURCE FILE\n");
return 0;
}
des=fopen("NewProgram.txt","wb");//opening/creating the
//destination file in write binary mode
if(des==0)//fopen returns NULL if there is error
{
printf("ERROR OPENING THE DESTINATION FILE\n");
return 0;
}
removeComments();//calls the remove comments function to
//remove the comments
fclose(src);//closing the source
fclose(des);//closing the destination
return 0;
}//end of main
void removeComments()
{
int curr,next;//creating the current and next character as
//int as they might require comparison with EOF i.e.-1
while((curr=fgetc(src))!=EOF)//the while loop runs till the
{ //end of file is reached
if(curr=='/')//probable beginning of a comment
{
curr=fgetc(src);//reading the next character from src
if(curr=='/')//single-line comment encountered
{
while((curr=fgetc(src))!='\n');//scan till an Enter is encountered
fputc(curr,des);//writing the '\n' scanned last
//to the destination file
}//end of if
else if(curr=='*')//a multi-line or documentation encountered
{
next=fgetc(src);//scaning the next character
while(!(curr=='*'&&next=='/'))//the loop runs till
{ //the */ is encountered
curr=next; //moving through the file in turn of
next=fgetc(src);//two characters
}//end of while
}//end of else if
else//situation where / was scanned but the next element was not a /
//because if / was scanned and the next is * then definitely a block comment
//has started
{
fputc('/',des);
fputc(curr,des);
}
}//end of other if
else if(curr=='"')//handling the string
{
fputc(curr,des);//writing the opening " to the file
while((curr=fgetc(src))!='"')
fputc(curr,des);
fputc(curr,des);//writing the closing " to the file
}//end of else if
else//dealing the normal code
fputc(curr,des);//writing them to the destination file
}
}
关于c - 我的用于删除C文件中注释的代码版本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54599634/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!