Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
need to do a coding about online registration to visit a farm. In the coding, I need to put about name and password for the registered user and make like if else for new user. I also need to put choose a date to visit at the end of the coding. In the coding, I must include array, pointer, loop, file and everything in C programming. I hope somebody can help me since I am really really struggling with programming. I really hope someone helps me. Thank you


What I have tried:

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

struct login
{
    char fname[30];
    char lname[30];
    char username[30];
    char password[20];
};

void login (void);
void registration (void);

int main (void)
{
    int option;

    printf("Press '1' to Register\nPress '2' to Login\n\n");
    scanf("%d",&option);

    getchar();

    if(option == 1)
        {
            system("CLS");
            registration();
        }

    else if(option == 2)
        {
            system("CLS");
            login();
        }
}

void login (void)
{
    char username[30],password[20];
    FILE *log;

    log = fopen("login.txt","r");
    if (log == NULL)
    {
        fputs("Error at opening File!", stderr);
        exit(1);
    }
Posted
Updated 21-May-21 21:36pm

You have your file section started. The code opens the file but doesn't read anything from it or close it. Here is the documentation of a couple of very useful functions for working with files : C++ reference : fopen[^]
C++ reference : fgets[^]
 
Share this answer
 
The problem is that you haven't done any of your task - and you are "struggling with programming" because you probably haven't done your earlier tasks. If you had, you'd have a better idea how to get started with this one!

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900