#I'm confused, could anyone help me?

70 messages · Page 1 of 1 (latest)

unkempt loomBOT
#

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.

carmine acorn
#

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 | }
      | ^

pliant goblet
#

I mean the errors are pretty self-explanatory, no?

unborn iron
#

usuario is of type float, and you try to put a char pointer into it

#

yeah

pliant goblet
#

Also you should definetly change the way you format your code

carmine acorn
carmine acorn
#

thanks both

unborn iron
#

👍

carmine acorn
#

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

pliant goblet
#

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)

unborn iron
#

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

pliant goblet
carmine acorn
carmine acorn
pliant goblet
#

Online editors are great for short tests, but for actually programming I would always recommend an IDE

carmine acorn
#

he doesnt wnat

carmine acorn
#

online editor is bad as crap

#

but no other thing

pliant goblet
#

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

unborn iron
carmine acorn
#

But i mean, could i do it other way?

#

because im seeing something

#

that could work

unborn iron
#

try other way

#

👍

pliant goblet
#

!vla

unkempt loomBOT
# pliant goblet !vla
What Is a VLA, and Why Is It "Bad"?

A Variable Length Array (VLA) is an array where the size is not constant and depends on a variable.

Example
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]
Why Are VLAs "Bad"?

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.

Compiler Support

: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

pliant goblet
#

Same for the contrasena array

pliant goblet
unborn iron
#

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 !

pliant goblet
#

you're welcome ^^

unborn iron
#

: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

pliant goblet
#

:D

unborn iron
#

so I've been mallocing() ever since for this case not knowing why

#

very epic

pliant goblet
#

So accidently got onto the right track, nice

unborn iron
#

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

pliant goblet
#

oh no, haha

#

!f

unkempt loomBOT
#


#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 */
ullenjoyer
pliant goblet
#

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

unkempt loomBOT
#

@carmine acorn Has your question been resolved? If so, type !solved :)

pliant goblet
#

Also scanf("%s", ...) is amongst the unsafest things you can do

carmine acorn
#

thanks both lads

#

i will try do one thing and then come back if it doesnt work

#

!solved

unkempt loomBOT
#

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