How to write a sentence to a text file in C

1 Answer

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

int main(void)
{   
    char sentence[100] = "I like programming";
    FILE *fp;

    fp = fopen("d://data.txt", "w");
    if (fp == NULL)
    {
        printf("Error Open File");
        exit(1);
    }
   
    fprintf(fp,"%s", sentence);
   
    fclose(fp);
            
    return 0;
}

  
/*
run:

data.txt
--------
I like programming

*/

 



answered Jun 3, 2017 by avibootz

Related questions

1 answer 315 views
1 answer 302 views
1 answer 376 views
1 answer 325 views
325 views asked Aug 19, 2017 by avibootz
2 answers 364 views
1 answer 285 views
285 views asked Jul 15, 2015 by avibootz
1 answer 292 views
292 views asked Oct 15, 2014 by avibootz
...