Writing to a file Using C Programming
Posted by Samath
Last Updated: February 25, 2012

#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("Errorin 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();

}