Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Here is a program in C that illustrates the use of fprintf() to write a text file:

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

int main()
{

printf("Welcome to DataFlair tutorials!

");

char character;
FILE *fpointer;
fpointer = fopen("C:program.txt","w"); // Here "w" refers to write on file
if(fpointer == NULL)
{
printf("Error! The file does not exist.");
exit(0);
}
printf("Enter a character: ");
scanf("%c",&character);

fprintf(fpointer,"%c",character); // Use of fprintf() function
fclose(fpointer);

return 0;
}
 
PREVIOUS NEXT
Tagged: #Here #program #C #illustrates #write #text
ADD COMMENT
Topic
Name
1+7 =