Thread: Error

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    Quote Originally Posted by SKeane
    On a PC, Unix box?
    Unix PC 64bit

  2. #17
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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

  3. #18
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Presumably Linux? In which case

    man 3 echo

    look at int noecho() and int echo() functions.

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    FreeBSD

  5. #20
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    The difference is that a char is an area in memory (about 8 bits), that your compiler will dedicate to a character.
    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?

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    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?

  7. #22
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    You have to turn off terminal echoing. Does FreeBSD not have a man page on echo?

  8. #23
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    I understand I should turn off terminal echoing, but I don't know how to do it in C... Can anyone help me?

  9. #24
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Did you do a man 3 echo?

  10. #25
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    Yes I did, but it doesn't work, I get a segmentation fault:

    Code:
    #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$ gcc -o quiet -lcurses quiet.c
    ~/C$ ./quiet
    Segmentation fault: 11 (core dumped)
    ~/C$

  11. #26
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Take the '&' off answer in the scanf().

    Code:
    scanf ("%s", answer);

  12. #27
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    Still the same error, it works fine when I delete the noecho() line...

  13. #28
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > 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.

  14. #29
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    Ok, thank you guys very much for your help

  15. #30
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM