When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
70 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
The words you don't underestand, are in spanish, forget them
error:
login.c: In function ‘user_login’:
login.c:17:40: error: incompatible types when assigning to type ‘float’ from type ‘char *’
17 | for(i=0;i<meta;i++){usuario[i]=db_username;contrasena[i]=db_password;}
| ^~~~~~~~~~~
login.c:17:66: error: incompatible types when assigning to type ‘float’ from type ‘char *’
17 | for(i=0;i<meta;i++){usuario[i]=db_username;contrasena[i]=db_password;}
| ^~~~~~~~~~~
login.c:21:20: error: incompatible types when assigning to type ‘float’ from type ‘char *’
21 | usuario[i]=user_toprove;
| ^~~~~~~~~~~~
login.c:22:23: error: incompatible types when assigning to type ‘float’ from type ‘char *’
22 | contrasena[i]=pass_toprove;
| ^~~~~~~~~~~~
login.c: At top level:
login.c:48:5: error: expected identifier or ‘(’ before ‘return’
48 | return output;
| ^~~~~~
login.c:49:1: error: expected identifier or ‘(’ before ‘}’ token
49 | }
| ^
I mean the errors are pretty self-explanatory, no?
Also you should definetly change the way you format your code
Not for me
ohhh
I know, trying to do it
thanks both
👍
But asking, could i just change it to char and the thing work whitout a for?
I want to usuario get a especific value when a while is done
Your IDE should support an auto-formatting.
E.g. for CLion it's Ctrl + Alt + L or for VS Code it's Shift + Alt + F (Windows), Shift + Option + F (Mac), Ctrl + Shift + I (Linux)
if you made it into a char then it would only have the first letter of the username
but you want to put the whole username inside the usuario right
this?
Why are you using an online editor?
let me explain because i cannot underestand
I want to get a data from a db where it's a user and a password.
The user introduce user and password and the program checks
Because visual studio code wont work
Online editors are great for short tests, but for actually programming I would always recommend an IDE
he doesnt wnat
recomend me one
online editor is bad as crap
but no other thing
CLion, VS or VS Code.
I've only ever used CLion and VS Code, but I've heard from many that VS is the best thing for Windows
Idk why VS Code doesn't work for you, probably because you didn't set it up correctly
float usuario[n];
Change To
char* usuario[n];
you gor it
I will try, thanks
Okay
But i mean, could i do it other way?
because im seeing something
that could work
Btw, when he does that then n == 0, so not only is this a VLA but it's also an array of length 0, which means accessing any index is UB
!vla
A Variable Length Array (VLA) is an array where the size is not constant and depends on a variable.
int size = rand();
int vla[size]; // VLA of type int[size]
int not_vla[10]; // regular array of type int[10]
constexpr int size = 10;
int arr[size]; // also not a VLA, of type int[10]
VLAs have poor compiler support and can lead to unsafe code. The core issue with VLAs is that the compiler doesn't know the size of the stack frame. Without warning flags like -Wvla, it can be easy to create a VLA by accident, even in C++ with some compilers.
:white_check_mark: available since C99
:no_entry: not available in C++ at all
:no_entry: was never supported by MSVC
:warning: optional feature since C11
:warning: supported as non-standard extension by GCC, clang
Same for the contrasena array
But yeah, for the online IDE this would be the button
missed the part where n is zero, you right
oh shit
I just realized
this VLA thing
I was trying to research it but couldn't find info
this blurb helps a lot, thanks !
you're welcome ^^
:D
I compile my code using gcc and my compiler was aok with using VLAs
and when I put in visual studio it told me that its not nice
:D
So accidently got onto the right track, nice
yeah it was pure accident, I don't use visual studio at all
haha
I then checked my gcc options and it turned out i misspelled the Werror stuff I prepared so it wasn't complaining for anything
#include <stdio.h>
#include <string.h>
int user_login(FILE* user) {
char username[255], password[255], db_username[255], db_password[255],
pass_toprove[255], user_toprove[255];
int output = 0, n = 0, i = 0, meta = 0;
float usuario[n], contrasena[i];
if (fopen("user.txt", "r") == NULL) {
return 3;
} else {
rewind(user);
}
printf("user: ");
scanf(" %s", username);
printf("pass: ");
scanf(" %s", password);
while (fscanf(user, "%s %s", db_username, db_password) != EOF) {
// hay un problema, te pide con el mismo usuario sin cambiar que le
// introduzcas una contraseña y se queda estacionado en el primero
meta++;
for (i = 0; i < meta; i++) {
usuario[i] = db_username;
contrasena[i] = db_password;
}
}
for (i = 0; i < meta; i++) {
usuario[i] = user_toprove;
contrasena[i] = pass_toprove;
while ((strcmp(username, user_toprove) != 0) ||
(strcmp(password, pass_toprove) != 0)) {
printf("Try again \n");
printf("user: ");
scanf(" %s", username);
printf("pass: ");
scanf(" %s", password);
}
}
while ((strcmp(username, db_username) != 0) ||
(strcmp(password, db_password) != 0)) {
n++;
if (n == 3) {
printf("login limits reached. db stopped.\n");
return 4;
}
}
if ((strcmp(username, db_username) == 0) &&
(strcmp(password, db_password) == 0)) {
printf("Succefull loged in, %s.", username);
output = 1;
} else {
return 2;
}
}
return output;
}
/* re escribir esta parte */
Okay, and as you may be able to see now that the code is properly formatted you also have a massive problem because the return output line is entirely outside of the function
@carmine acorn Has your question been resolved? If so, type !solved :)
thanks both lads
i will try do one thing and then come back if it doesnt work
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity