ansi c write unsigned short to file

#include <stdio.h>

int main() {
    FILE *file;
    unsigned short data = 12345; // Example value, replace with your own data

    // Step 1: Open the file in binary write mode
    file = fopen("output.bin", "wb");

    // Step 2: Check if the file was opened successfully
    if (file == NULL) {
        perror("Error opening file");
        return 1;
    }

    // Step 3: Write the unsigned short data to the file
    fwrite(&data, sizeof(unsigned short), 1, file);

    // Step 4: Close the file
    fclose(file);

    return 0;
}