G.B
G.B

Reputation: 45

Printing to a text file in c using strings

I want the program to print the word hello to the text file by means of strings.

#include <stdio.h>

void main ()
{
    char word[10] = {"hello"};
    FILE*fp;
    fp = fopen("C:\\temp\\Dictionary.txt", "w+"); 

    fprintf(fp, word[0]);
}

Upvotes: 1

Views: 517

Answers (1)

Seva
Seva

Reputation: 2488

You're printing first char instead of the string. And it might not be a valid format either. Correct call will be fprintf(fp, "%s", word). And don't forget to close file too.

Upvotes: 2

Related Questions