954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

can any body explain this program

Hi,

the concept of the program is enter a piece of text from the keyboard and place that piece of text into a file

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void main()
{
	 FILE *fp;
	 char s[80];
	 fp=fopen("new.txt","w");
	 if(fp==NULL)
	 {
		  printf("unable to open file");
		  exit(1);
	 }

	 printf("enter new line of text:\n");
	 while(strlen(gets(s))>0)
	 {
		 fputs(s, fp);
		 fputs("\n", fp);
	 }
	 fclose(fp);

	}

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,

sambafriends
Newbie Poster
21 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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 .

devnar
Junior Poster
149 posts since Sep 2008
Reputation Points: 124
Solved Threads: 18
 

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

sambafriends
Newbie Poster
21 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

Main() must return a zero for successful operation.

MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
 

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. :P

devnar
Junior Poster
149 posts since Sep 2008
Reputation Points: 124
Solved Threads: 18
 

As for your program, I don't see anything wrong with it. I even ran it and got input written to new.txt.

devnar
Junior Poster
149 posts since Sep 2008
Reputation Points: 124
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You