First C project, Need help

Hello, I have been learning C for around 2 days and I find it to be very easy because I already know the basics of c++. Here is my first C project.

Im trying to make a very small and simple database in C. The code that I am showing has no errors or compiling issues, but when I try to call my voids, It crashes. I need help. There are other issues with this program but not being able to call my voids is the main one.

#include <stdio.h>
#include <stdlib.h>
struct{
    char name[50];
    int age[50];
    char account;
    char adress[50];
    char pin[50];
}Add, Chan;

void editinfo(){
    int c;
    char a;
    FILE *Old, *New;
    Old = fopen("Smoot", "smeet");
    New = fopen("Sig", "Smock");
    while(a != 1){
        printf("Enter account pin: ");
        scanf(Add.pin);
        if(a == Chan.pin){
            system("clear");
            printf("Please enter all new info\n\n");
            printf("Name: \n", Add.name);
            printf("Adress: \n", Add.adress);
            printf("what do you want to change: \n");
            scanf("%s", a);
            if(a == "name" || "Name"){
                printf("Enter new name: \n");
                scanf(Add.name);
            }
            if(a == "Adress" || "adress"){
                printf("Enter new adress: \n");
                scanf("%s", Add.adress);
            }
            printf("New info saved");

            if(a != Add.pin){
                printf("1 = New account\n");
                printf("2 = Try again\n");
                printf("Unknown pin, would you like to make a new account or try again: ");
                scanf("%d", c);
                if(c == "1"){
                    NewPerson();
                if(c == "2"){
                    a = 1;
                }
            }
        }
    }
    fclose(Old);
    fclose(New);
    remove("Smoot");
    rename("Sig", "Smoot");
    }
}
void NewPerson(){
    int c;
    const pinsize = 4;
    FILE *yeet;
    yeet = fopen("Smoot", "smeet");
    while(c == 1){
        printf("Enter account pin: ");
        scanf("%s", Add.pin);
        if(Add.pin > pinsize){
            c = 1;
        }
    }
    printf("add account");
    printf("enter name: \n");
    scanf("%s", Add.name);
    printf("enter address: \n");
    scanf("%s", Add.adress);
    printf("Enter birthdate: \n");
    scanf("%s", Add.age);
    fclose(yeet);
    system("clear");
    printf("info saved!\n");
}
int main(char c){
    printf("Info tracker\n\nedit\nnew\n\nEnter your funtion: ");
    scanf("%s", c);
    if(c == "edit" || "Edit"){
        editinfo();
    }
    if(c == "new" || "New"){
        NewPerson();
    }
    return 0;
}

Two errors and lots of warnings when I tried to compile it.

first:

ethan.c:58:6: error: conflicting types for 'NewPerson'
void NewPerson(){
     ^
ethan.c:45:21: note: previous implicit declaration is here
                    NewPerson();
                    ^

Just reverse the order and it compiles (don’t know if it runs).

I think it’s because you reference NewPerson() inside editinfo() before defining it.

So I just tried, and moved NewPerson() definition before the editinfo() and that error disappeared.

Second error was

ethan.c:81:5: error: first parameter of 'main' (argument count) must be of type 'int'
int main(char c){
    ^

Which basicaly says that your main has to be an int, not a character.

Hope that helps.

What compiler are you using? When I tried to compile with gcc on macOS, it gave a bunch of warnings as well, like:

ethan.c:52:18: warning: comparison between pointer and integer ('int' and 'char *')
            if(a == "name" || "Name"){
               ~ ^  ~~~~~~
ethan.c:54:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
                scanf(Add.name);
                      ^~~~~~~~
ethan.c:56:18: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare]
            if(a == "Adress" || "adress"){
                 ^  ~~~~~~~~
ethan.c:56:18: warning: comparison between pointer and integer ('int' and 'char *')
            if(a == "Adress" || "adress"){
               ~ ^  ~~~~~~~~

Which means you’re confusing variable types, I think.

If this is your first C program, then two things:

  • Congrats! It’s awesome you’re trying to learn this on your own. I’m not a coder at all, but it’s great to see someone try and learn new languages.

  • Start smaller :slight_smile: Try something that’s a few lines then expand that, instead of starting big :slight_smile:

Thanks, For some reason my the code::blocks IDE says it has no errors or warnings.

Is this on Linux?

Try just using a text editor and gcc as a compiler.