Run a C program?

ok try this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define MAX_USERNAME_LENGTH 100

int main() {
    char username[MAX_USERNAME_LENGTH];
    char color[10];
    FILE *fp;

    printf("Welcome to OyoSoft Setup!\n");
    sleep(1);

    printf("Please enter a username: ");
    scanf("%s", username);

    fp = fopen("././home.u/sys/usrnme.txt", "w");
    if (fp == NULL) {
        printf("Error opening file.\n");
        exit(1);
    }
    fprintf(fp, "%s", username);
    fclose(fp);

    printf("Please choose a color theme (white, blue, green, red): ");
    scanf("%s", color);

    fp = fopen("././home.u/sys/color.txt", "w");
    if (fp == NULL) {
        printf("Error opening file.\n");
        exit(1);
    }
    fprintf(fp, "%s", color);
    fclose(fp);

    printf("Setup complete!\n");

    return 0;
}

basically, you need a function called main XD. You can pair it with this in shell:

cd home.u/user
cc setup.c -o output
chmod +x setup.c
./output
rm -rf output

I appreciate your help, and it did work, but now in my code, when I enter a username, it says error opening file, which means it can’t open the directory or the file. Is this a programming error or a permission issue?

Oh and yes. This is what I meant. I know that I needed a function called main. But it is needed by main.c, so when I try to run the program, I now get this error, which happened before.
Screen Shot 2023-03-04 at 2.50.05 PM

oh sorry then I don’t know what to do XD BTW if you ever want to use that code again, use freopen instead and just use printf with it

Thank you for trying to help regardless

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.