#include <stdio.h>
#include <string.h>
int main()
{
//file pointer
FILE *fp = NULL;
//Message
char * message = "I love Aticleworld.com";
//Variable for message length
int length = 0;
//create and open the texr file
fp = fopen("aticleworld.txt", "w");
if(fp == NULL)
{
printf("Error in creating the file\n");
exit(1);
}
//Get the length of message
length = strlen(message);
//write the length in file
fprintf(fp,"%d",length);
//write the message in file
fprintf(fp,"%s",message);
//Close the file
fclose(fp);
return 0;
}
Output:
In the below image, you can see the fprintf write the 22 (message length) in string format, so it is showing as it as 22.
Output:
In the below image, you can see the fprintf write the 22 (message length) in string format, so it is showing as it as 22.
![](https://nerdutella.com/assets/dropzone/uploads/tinymce_images/questions/22393/answers/blobid0.png)
need an explanation for this answer? contact us directly to get an explanation for this answer