Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
C file write example 
 

Here we are using the library function fwrite() to write the data into the file.

 

C file write example

                         

This section demonstrates you to write the data into the file.

Here we are using the library function fwrite() to write the data into the file. You can see in the given example, we have stored the string into the buffer which is to be written into the specified file 'Hello.txt'. The type FILE stores all the information related to file stream. The function fopen(file, "w") opens the file and allow to perform write operations into the file. The library function strlen() provided by the header file <string.h> determines the length of the string which is stored into buffer. The function fwrite(buffer, len, 1, p) write the buffer value into the file and fclose() function closes the file stream and flushes the buffer.

Here is the code:

FILEWRIT.C

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

void main() {
  FILE *p = NULL;
  char *file = "C:\\Hello.txt";
  char buffer[80"Don't look for endings when you need a beginning.";
  size_t len = 0;
  p = fopen(file, "w");
  if (p== NULL) {
    printf("Error in opening a file..", file);
  }
  len = strlen(buffer);
  fwrite(buffer, len, 1, p);
  fclose(p);
  printf("\nWritten Successfuly in the file.\n");
  if (buffer != NULL)
    free(buffer);
  getch();
}

When you run the above example, the string will get stored into the file and shows the message:

Download Source Code:

                         

» View all related tutorials
Related Tags: c ide function language fun io pointer vi int id address define poi unc add to point attach feature base

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.