Unix PC 64bitOriginally Posted by SKeane
Unix PC 64bitOriginally Posted by SKeane
The difference is that a char is an area in memory (about 8 bits), that your compiler will dedicate to a character.
char*, instead, points to an area in memory that is supposed to contain a char. (Plus char* are more than 8bits I think).
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
Presumably Linux? In which case
man 3 echo
look at int noecho() and int echo() functions.
FreeBSD
Plus you are locally hiding the x in the outer scope, which is usually not a good thing. Why do you need a 'local' x in the loop?The difference is that a char is an area in memory (about 8 bits), that your compiler will dedicate to a character.
Well, don't know why I needed that? I'm very new to C so it's hard working with the *'s and stuff.
Does anyone of you know how to hide things you type? It's for password stuff, so I want it to be printed as stars or not printed at all, is this possible?
You have to turn off terminal echoing. Does FreeBSD not have a man page on echo?
I understand I should turn off terminal echoing, but I don't know how to do it in C... Can anyone help me?
Yes I did, but it doesn't work, I get a segmentation fault:
~/C$ gcc -o quiet -lcurses quiet.cCode:#include <curses.h> #include <stdio.h> #include <string.h> int main (int argc, char **argv) { char *answer = malloc(64*1); noecho(); printf ("Pass? "); scanf ("%s", &answer); return 0; }
~/C$ ./quiet
Segmentation fault: 11 (core dumped)
~/C$
Take the '&' off answer in the scanf().
Code:scanf ("%s", answer);
Still the same error, it works fine when I delete the noecho() line...
> If I want to ask a password, how can I make sure it's printed as *'s or it isn't printed at all?
Not to insult or talk over Skeane, but the C FAQ item 19.1 goes into this with exhaustive detail. I suspect you are getting a segmentation fault because you're using the curses library without setting up a WINDOW.
Ok, thank you guys very much for your help
If you want to continue in the vein you are ...
Code:#include <curses.h> #include <stdio.h> #include <string.h> int main (int argc, char **argv) { char *answer = malloc(64*1); (void) initscr(); (void) raw; (void) noecho(); printw ("Pass? "); refresh(); scanf ("%s", answer); (void) echo(); endwin(); printf("You entered %s\n", answer); return(0); }
Otherwise follow citizen's advice.
Last edited by SKeane; 10-12-2006 at 04:45 AM.