I am new to C so I started playing around with some code. I have a bug in my code as I believe using printf(pass)
is not safe to use because it can overwrite the value and hence not safe for the user. I was wondering am I right about it that printf(pass)
is not safe in my code? Also, how can I still let user print the message finally logged in
without changing my code. Is there any way to do that?
My code:
#include <stdio.h>
char pass[100];
char getPass() {
int value = 'G';
int * j = & value;
fgets(pass, sizeof(pass), stdin);
printf("your entered pass is ");
printf(pass);
return (char)( * j);
}
void main() {
printf("enter the pass here ");
if (getPass() == 'K') {
printf("finally logged in\n");
exit(0);
} else {
printf("Wrong password\n");
exit(1);
}
}