Write a line of text (character by character) in a file ! and display its content

#include <stdio.h>

int main(void)
{
    char ch;
    FILE *p;

    //opening file to write on it
    p = fopen("text.txt""w+");
    printf("enter the sentence : ");
    while ((ch = getchar()) != '\n'//user can type until they press enter
    {
        fputc(ch, p);
    }
    fclose(p);

    //opening file in read mode to read its content
    printf("content of file : ");
    p = fopen("text.txt""r");
    while (!feof(p))
    {
        ch = fgetc(p);
        printf("%c", ch);
    }
    fclose(p);
}
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment