can any body explain this program

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 21
Reputation: sambafriends is an unknown quantity at this point 
Solved Threads: 0
sambafriends sambafriends is offline Offline
Newbie Poster

can any body explain this program

 
0
  #1
Nov 24th, 2008
Hi,

the concept of the program is enter a piece of text from the keyboard and place that piece of text into a file
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  
  6. void main()
  7. {
  8. FILE *fp;
  9. char s[80];
  10. fp=fopen("new.txt","w");
  11. if(fp==NULL)
  12. {
  13. printf("unable to open file");
  14. exit(1);
  15. }
  16.  
  17. printf("enter new line of text:\n");
  18. while(strlen(gets(s))>0)
  19. {
  20. fputs(s, fp);
  21. fputs("\n", fp);
  22. }
  23. fclose(fp);
  24.  
  25. }
But, after completing this program
when I open the text file there is no result at all
what is the problem is it really write the contents to a new.txt file or not. If yes please explain briefly why my text file is not changin
else please give the solution
regards,
Last edited by Narue; Nov 25th, 2008 at 9:42 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: devnar will become famous soon enough devnar will become famous soon enough 
Solved Threads: 16
devnar's Avatar
devnar devnar is offline Offline
Junior Poster

Re: can any body explain this program

 
1
  #2
Nov 24th, 2008
This is your 14th post, and you still don't bother to use code tags. Also it was mentioned quite a lot of times in your previous thread that you should use int main instead of void main .
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: sambafriends is an unknown quantity at this point 
Solved Threads: 0
sambafriends sambafriends is offline Offline
Newbie Poster

Re: can any body explain this program

 
0
  #3
Nov 25th, 2008
thanku for ur patience replies

Sorry but what is the exact difference between void main and int main
I know only one thing void is a data type which specifies the function doesn't return any value.

any thing gr8 diffrence between these two can u explain please


regards,
samba
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 980
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: can any body explain this program

 
0
  #4
Nov 25th, 2008
Main() must return a zero for successful operation.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: devnar will become famous soon enough devnar will become famous soon enough 
Solved Threads: 16
devnar's Avatar
devnar devnar is offline Offline
Junior Poster

Re: can any body explain this program

 
0
  #5
Nov 25th, 2008
Read this article.
There's a very well explained article by Steve Summit about the incorrect usage of main's return type. It's in the link pasted above. Anyway, here's a direct link. It certainly helped me when I was trying to understand what all the noise about main's return type was... which wasn't very long back actually.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: devnar will become famous soon enough devnar will become famous soon enough 
Solved Threads: 16
devnar's Avatar
devnar devnar is offline Offline
Junior Poster

Re: can any body explain this program

 
0
  #6
Nov 25th, 2008
As for your program, I don't see anything wrong with it. I even ran it and got input written to new.txt.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 423 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC