-3

So I have an assignment for hs and honestly I do not know how to program in C so I would appreciate all the help I can get.

Anyways my problem is that I cannot for the life of me read a content of a file, asign it to a variable and compare it to another variable if the content is the same.

I am making a login interface with already pre-input admin email and admin password and here is my mess of a code for now:

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

int main()
{
    FILE *emailf;
    emailf = fopen("email.txt", "r");
    char* fgets(char* emailx){
    return emailx;
    }
    fclose(emailf);
    char email [30];
    char password [16];
do{
    printf("E-mail:");
    scanf("%c", &email);


    }
    while (email != emailx);

What it does is tells me that emailx variable is not even declared so if you could help me I would be glad! And also it does not have to resemble this code since I do not know jack crap about C programming language so if you could tell me a different way to try what I am trying would be good as well. Thank you!

0m3rk4
  • 1
  • 1
    `I do not know jack crap about C programming language` - start with a C tutorial or book, for example K&R. You cannot write code in C if you don't know C. – Arkadiusz Drabczyk Jan 06 '21 at 19:34
  • I suggest that you buy [a good book](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) (beginner's level) to learn C properly. – Andreas Wenzel Jan 06 '21 at 19:51
  • Please have a look at [this post](https://meta.stackoverflow.com/a/334823/3637535). Stack Overflow is not the right place to ask someone to do your homework. – Asad Ali Jan 06 '21 at 20:00
  • The following is wrong with your code: (1) You should always check the return value of `fopen` to verify that the operation was successful. (2) Local function definitions are disallowed in C. (3) `scanf("%c", &email);` will only read a single character, not an entire e-mail address. (4) The expression `while (email != emailx);` will only compare the pointers. Use `strcmp` instead to compare the actual string contents. Since you probably don't understand half of what I am saying, I strongly suggest that you follow the advice about buying a book. – Andreas Wenzel Jan 06 '21 at 20:07

1 Answers1

1

There are several things that are not good in your program.

Firstable, are you sure you are openning properly the file "email.txt" ?

Then, this part of the code is wrong, you cannot define a function inside a function, especially if this function already exist in a library:

 char* fgets(char* emailx){
return emailx;
}

maybe you should try something like

emailx = fgets(emailx);

But first you should declare your variable.

I ve never used those functions so I don t know how it works precisely, but chek the manual.

UnDesSix
  • 68
  • 1
  • 1
  • 8