i am unable solve the error in my program

Dani AI

Generated

Agreeing with : we need the exact compiler output, the line numbers, and the smallest code sample that still triggers the error. If you cannot post the whole car-rental project, trim it down to just the login flow and a tiny users file. This checklist helps: compiler and version, compile flags, full error text, sample input, and the minimal code. See this quick guide on making a minimal repro for what to include: How to create a Minimal, Reproducible Example.

Common login bugs in C for this kind of assignment:

  • Mixing scanf with fgets and leaving a stray newline in the input buffer. Prefer fgets for all user input and then strip the newline. fgets
  • Comparing C strings with == instead of strcmp.
  • Using unsafe reads like gets or scanf("%s", buf) without a width.
  • Parsing credential files with fscanf format bugs; fgets + sscanf is simpler and safer.

Here is a tiny, working login skeleton you can compare against:

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

static void chomp(char *s) { s[strcspn(s, "\n")] = 0; }

int check_login(const char *user, const char *pass, const char *path) {
    FILE *fp = fopen(path, "r");
    if (!fp) return 0;
    char line[128], u[32], p[32];
    while (fgets(line, sizeof line, fp)) {
        if (sscanf(line, "%31[^,],%31s", u, p) == 2) {
            if (strcmp(user, u) == 0 && strcmp(pass, p) == 0) {
                fclose(fp);
                return 1;
            }
        }
    }
    fclose(fp);
    return 0;
}

int main(void) {
    char user[32], pass[32];
    printf("User: "); if (!fgets(user, sizeof user, stdin)) return 1; chomp(user);
    printf("Pass: "); if (!fgets(pass, sizeof pass, stdin)) return 1; chomp(pass);
    puts(check_login(user, pass, "users.csv") ? "OK" : "Invalid");
}

Compile and run with extra checks to catch the real cause quickly:

gcc -Wall -Wextra -pedantic -fsanitize=address -g login.c -o login
./login

AddressSanitizer will point to buffer overflows and use-after-free errors with exact lines: AddressSanitizer.

Post back with your error and a small snippet like the above, and folks here (paging and ) can be very specific.

Recommended Answers

All 2 Replies

That's too bad. I've been there myself.

We would need a lot more information than that to be able to help you with it, starting with the code in question and the error you are getting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.