C and files

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey i'm trying to learn C and I'm using Code Blocks IDE.

Just struggling to get this from the latest tutorial I'm following, I'm trying to write some text to a file and then read it and display it, this is what I have but isn't doing the reading/displaying bit correctly:

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

FILE *output_file;

int main()
{
    char str [80];

    if ((output_file = fopen("output_file", "w")) == NULL)
        fprintf(stderr, "Cannot open %s\n", "output_file");

    fprintf(output_file, "Hi there");

    fscanf(output_file, str);
    printf(str);

    fclose(output_file);

    return 0;
}
 
Back
Top Bottom