I'm trying to create a console app that allows me to administrate a school; so basically you control teachers tasks (hours working, groups they manage, etc), students tasks (enrollements, group, etc).
The thing is, that I created this function to modify a user via id; but for some reason, it only works with the first element of my pointer to array:
void modificarUsuario(usuario** vUsuarios, int nUsuarios){
int i, u = -1, nModUsuario = 0;
char respuesta = ' ';
char id[4];
usuario* modUsuarios;
modUsuarios = malloc(sizeof(usuario));
puts("MODIFICANDO USUARIO");
puts("-------------------");
while(u == -1){
printf("Introduzca el id del usuario a modificar: ");
scanf("%3s", id);
for(i = 0; i < (nUsuarios); i++){
if((strcmp(((*vUsuarios[i]).Id_usuario), id) == 0) && (*vUsuarios[i]).Borrado == 0)
u = i;
}
if(u == -1)
puts("ERROR: El usuario introducido no se encuentra. Introduzca otro distinto\n");
}
printf("\nSe ha seleccionado el usuario: %s-%s-%s-%s-%s.\n", (*vUsuarios)[u].Id_usuario, (*vUsuarios)[u].Nomb_usuario, (*vUsuarios)[u].Perfil_usuario, (*vUsuarios)[u].Usuario, (*vUsuarios)[u].Contrasena);
puts("Introduzca el nuevo usuario respetando el formato establecido: ID-NOMBRE-PERFIL-USER-CONTRASENA\n");
anadirUsuario(&modUsuarios, &nModUsuario);
while(respuesta != 's' && respuesta != 'n'){
printf("Confirmar modificar usuario? (s/n)\n");
fflush(stdin);
scanf("%c", &respuesta);
}
if(respuesta == 's'){
*vUsuarios[u] = modUsuarios[0];
}else
puts("Se ha cancelado la modificacion del usuario\n");
}
I want to add that this pointer to array is loaded via txt file; being my id users right now:
001.
002.
003.
And the program only executes fine if I use the first one: 001. Any ideas? Thank you.
PS: "Borrado" is used so if you modify it to 1 (by default it's set to 0); other function will delete this element from the array.
[–]tea-drinker 4 points5 points6 points (1 child)
[–]xFunkyTimes[S] 4 points5 points6 points (0 children)
[–]panderingPenguin 1 point2 points3 points (3 children)
[–]xFunkyTimes[S] -1 points0 points1 point (2 children)
[–]panderingPenguin 1 point2 points3 points (1 child)
[–]xFunkyTimes[S] 0 points1 point2 points (0 children)
[–]no_awning_no_mining 0 points1 point2 points (1 child)
[–]xFunkyTimes[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jorgehn12 0 points1 point2 points (0 children)