I am a beginner in c programming. While I figured out how to read the content from my "credentials.txt" file, I cannot figure out how I can compare the username and password user enters with the contents in the text file. Also, any suggestions would be a welcome change.
Sign-Up code (saves username and password to a file):
#include <stdio.h>
#include <string.h>
int main()
{
    char username[19], password[19];
cred_enter_username:
    printf("Enter username (Max 18 characters): ");
    int len_u = strlen(gets(username));
    for (int i = 0; username[i] != '\0'; i++)
    {
        if (username[i] == ' ')
        {
            printf("No spaces allowed. Use only '_' or '-'. Try again\n");
            goto cred_enter_username;
        }
    }
    if (len_u > sizeof(username))
    {
        printf("\n");
        printf("Number of characters exceed allowed characters. Please try again");
        printf("\n\n");
        goto cred_enter_username;
    }
cred_enter_password:
    printf("Enter password (Max 18 characters): ");
    int len_p = strlen(gets(password));
    for (int i = 0; password[i] != '\0'; i++)
    {
        if (password[i] == ' ')
        {
            printf("No spaces allowed. Try again\n");
            goto cred_enter_password;
        }
    }
    if (len_p > sizeof(password))
    {
        printf("\n");
        printf("Number of characters exceed allowed characters. Please try again");
        printf("\n\n");
        goto cred_enter_password;
    }
    FILE *fptr = NULL;
    fptr = fopen("credentials.txt", "a");
    fprintf(fptr, "Username: %s\n", username);
    fprintf(fptr, "Password: %s\n", password);
    fprintf(fptr, "\n");
    fclose(fptr);
    return 0;
}
Log-In code (so far):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    FILE *credentials;
    char *buffer;
    long numbytes;
    char username[19], password[19];
    char userstr[30], passstr[30];
    credentials = fopen("credentials.txt", "r");
    if (credentials == NULL)
    {
        printf("No account found. Sign up first");
        return 1;
    }
    fseek(credentials, 0L, SEEK_END);
    numbytes = ftell(credentials);
    fseek(credentials, 0L, SEEK_SET);
    buffer = (char *)calloc(numbytes, sizeof(char));
    if (buffer == NULL)
    {
        printf("Memory Error");
        return 1;
    }
    fread(buffer, sizeof(char), numbytes, credentials);
cred_enter_username:
    printf("Enter username (Max 18 characters): ");
    int len_u = strlen(gets(username));
    for (int i = 0; username[i] != '\0'; i++)
    {
        if (username[i] == ' ')
        {
            printf("Invalid username. Try again\n");
            goto cred_enter_username;
        }
    }
    if (len_u > sizeof(username))
    {
        printf("\n");
        printf("Number of characters exceed allowed characters. Please try again");
        printf("\n\n");
        goto cred_enter_username;
    }
    
cred_enter_password:
    printf("Enter password (Max 18 characters): ");
    int len_p = strlen(gets(password));
    for (int i = 0; password[i] != '\0'; i++)
    {
        if (password[i] == ' ')
        {
            printf("Invalid. Try again\n");
            goto cred_enter_password;
        }
    }
    if (len_p > sizeof(password))
    {
        printf("\n");
        printf("Invalid password. Try again");
        printf("\n\n");
        goto cred_enter_password;
    }
    return 0;
}
 
     
    