Can comments in a C program only be one line?

烟雨青岚
Release: 2020-06-18 11:58:02
Original
6802 people have browsed it

Can comments in a C program only be one line?

#Can comments in a C program only be one line?

The comments of a C program may not be one line. There are multiple lines of comments in a C program. The usage is a block comment starting with /* and ending with */;

The other is starting with // and ending with a newline character. The closing line comment.

You can use the /* and */ delimiters to mark comments within one line, or to mark comments on multiple lines .

For example, in the following function prototype, the ellipsis means that the open() function has a third parameter, which is optional.

Comments explain the usage of this optional parameter:

int open( const char *name, int mode, … /* int permissions */ );
Copy after login

C language add comments

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
intmain()
{
intm,k=1,n;
charline1[256],line[256];//将文件中的数据读入到字符数组中
FILE*fpin=fopen("sourcefile.c","r");
if(fpin==NULL)
{
printf("sourcecodereaderror!\n");
exit(1);
}
FILE*fpout=fopen("targetfile.c","w+");
if(fpout==NULL)
{
printf("sourcecodewriteerror!\n");
exit(1);
}
printf("请输入m和n:");
scanf("%d%d",&m,&n);
intn1=0;
fgets(line1,255,fpin);
do
{
n1++;
if(n1>=m&&n1<m+k)
fputs("//",fpout);
fputs(line1,fpout);
fgets(line1,255,fpin);
}
while(!feof(fpin));
fseek(fpout,0,SEEK_SET);
fgets(line,255,fpout);
do
{
printf("%d\t%s",k,line);
k++;
fgets(line,255,fpout);
}
while(!feof(fpout));
fclose(fpout);
fclose(fpin);
return0;
Copy after login

Recommended tutorial: "C Language

The above is the detailed content of Can comments in a C program only be one line?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template