write array of char to file in c

#include <stdio.h>

int main() {
    char array[] = "Hello, this is a sample string.";
    FILE *file = fopen("output.txt", "w");

    if (file != NULL) {
        fprintf(file, "%s", array);
        fclose(file);
    }

    return 0;
}