Write a program to remove the C comments(/* */) and C++
comments(//) from a file.
The file should be declared in command line.
Answer Posted / sahil
/*Improved and working answer*/
#include<stdio.h>
void main()
{
FILE *fd;
int ch,flag,i;
char cc;
i=flag=0;
ch=0;
fd = fopen("file","r+");
// ch=fgetc(fd);
while((ch=fgetc(fd))!=EOF)
{ cc=ch;
flag = 0;
if(ch == '/')
{
ch = fgetc(fd);cc =ch;
if(ch == '*')
{
flag = 1;
while(1){
cc = fgetc(fd);
if(fgetc(fd) == '*' && fgetc(fd) == '/')
break;
}
}
else if(ch == '/')
{
flag = 1;
while(fgetc(fd)!= '/');
}
else{
printf("/");
}
}
if(!flag )
printf("%c",ch);
}
fclose(fd);
}
| Is This Answer Correct ? | 9 Yes | 13 No |
Post New Answer View All Answers
Differentiate between the expression “++a” and “a++”?
For what purpose null pointer used?
What should malloc(0) do?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
What are structure types in C?
Explain what are binary trees?
what do u mean by Direct access files? then can u explain about Direct Access Files?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
What is the c language function prototype?
What is malloc calloc and realloc in c?
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
Compare array data type to pointer data type
what is the structure pointer?
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.