write in file in c

#include <stdio.h>

int main() {
    FILE *file;
    char data[] = "Hello, this is a sample text to be written to the file.";

    file = fopen("output.txt", "w");
    if (file == NULL) {
        printf("Error opening file!\n");
        return 1;
    }

    fprintf(file, "%s", data);
    fclose(file);

    return 0;
}