Writing to .out file

Viewed 44

Is it possible to write integers to a ".out" file? I'm thinking something like below, but when I try it, the pointer just ends up as null.

#include <stdio.h>
int main() {
    int arrInt[] = {1, 2, 3, 4, 5};
    FILE* writeFile;
    writeFile = fopen("outFile.out", "w");
    for(int k = 0; k < 5; k++) {
        fprintf(writeFile, "%d", arrInt[k];
    }
    if(writeFile == NULL) {
        printf("File is NULL");
        exit(-1);
    }
    fclose(writeFile);
    return 0;
}

output:

File is NULL

If it's not possible, what would be a viable alternative? Thanks

EDIT: I already had all added suggestions, but added them here just to be clearer. I do want them to be a single line with no spaces or new lines, it's actually a much more complex problem, but I simplified it a lot just to understand this one piece.

0 Answers
Related