User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 373,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,859 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Oct 23rd, 2007
Views: 3,226
hello frnd this a c program that removes c c++ style comments
c Syntax | 4 stars
  1. //program to print a file by removing comments
  2. /*program*/
  3. #include<stdio.h>
  4. void main(int argc , char *argv[])
  5. {
  6. FILE *fp,*fp1;
  7. char ch;
  8. clrscr();
  9. fp=fopen(argv[1],"r");
  10. fp1=fopen(argv[2],"w");
  11. while(1)
  12. {
  13. ch=fgetc(fp); /*fgetc*/
  14. if(ch==EOF) //eof
  15. break;
  16. else
  17. {
  18. if(ch=='/')
  19. {
  20. ch=fgetc(fp);
  21. if(ch=='/')
  22. {
  23. while(1)
  24. {
  25. ch=fgetc(fp);
  26. if(ch=='\n')
  27. goto label;
  28. }
  29.  
  30. }
  31. if(ch=='*')
  32. {
  33. while(1)
  34. {
  35. ch=fgetc(fp);
  36. if(ch=='*')
  37. {
  38. ch=fgetc(fp);
  39. if(ch=='/')
  40. {
  41. while(1)
  42. {
  43. ch=fgetc(fp);
  44. goto label;
  45. }
  46. }
  47. else printf("*");
  48. }
  49. }
  50. }
  51. else printf("/");
  52. }
  53. }
  54. label:fputc(ch,fp1);
  55. }
  56. fclose(fp); /*closes the file*/
  57. fclose(fp1);
  58. }
Comments (Newest First)
thungmail | Newbie Poster | Feb 11th, 2008
hi
why you declare:
char =ch;
and then
ch=fgetc(fp);
I dont understand because fgetc(fp)'s return type is integer, but ch is char.
Tuan
hobbes78 | Newbie Poster | Dec 18th, 2007
Humm... This will fail on a program as simple as:
  1. #include <iostream>
  2.  
  3. use namespace std;
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. cout << "http://www.google.com/" << endl;
  8. return 0;
  9. }
niki01 | Newbie Poster | Nov 19th, 2007
Hi I'm writing a Program in C++, I believe the program is well written because the program was without error or warning. My problem is the program will not execute. I don't why it will not and don't know what to do. Please help me out.
jain_arhant | Newbie Poster | Oct 29th, 2007
is it possible to remove the goto statement in the code ?
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC