Write a program to remove the C comments(/* */) and C++
comments(//) from a file.
The file should be declared in command line.
Answer Posted / vadivel
#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *f;
int flag;
f = fopen(argv[1],"r");
while(!feof(f))
{
ch = fgetc(f),flag = 0;
if(ch == '/')
{
ch = fgetc(f);
if(ch == '*')
{
flag = 1;
while(1)
if(fgetc(f) == '*' && fgetc(f) == '/')
break;
}
else if(ch == '/')
{
flag = 1;
while(fgetc(f)!= '/n');
}
else
printf("/");// if it s division operator
}
if(!flag )
printf("%c",ch);
}
fclose(f);
}
/*
Run d prog as
>./a.out file_name.cpp
*/
Is This Answer Correct ? | 54 Yes | 47 No |
Post New Answer View All Answers
What are the two forms of #include directive?
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
Why do we use pointer to pointer in c?
What is variable in c example?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
What does void main return?
When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd
Where are some collections of useful code fragments and examples?
Explain what is the difference between a string and an array?
What is the c language function prototype?
Write a code to generate a series where the next element is the sum of last k terms.
What happens if a header file is included twice?