Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:06:26+00:00 2026-06-03T04:06:26+00:00

This is my code: void get_pass(char *p); int main(){ char *host, *user, *pass; host

  • 0

This is my code:

  void get_pass(char *p);

int main(){

    char *host, *user, *pass;

    host = malloc(64); /* spazio per max 64 caratteri */
    if(!host) abort(); /* se malloc ritorna NULL allora termino l'esecuzione */
    host[63] = '\0';   /* evitare un tipo di buffer overflow impostando l'ultimo byte come NUL byte */

    user = malloc(64);
    if(!user) abort();
    user[63] = '\0';

    pass = malloc(64);
    if(!pass) abort();
    pass[63] = '\0';

    /* Immissione di hostname, username e password; controllo inoltre i 'return code' dei vari fscanf e, se non sono 0, esco */
    fprintf(stdout,"--> Inserisci <hostname>: ");
    if(fscanf(stdin, "%63s", host) == EOF){
        fprintf(stdout, "\nErrore, impossibile leggere i dati\n");
        exit(EXIT_FAILURE);
    }
    fprintf(stdout,"\n--> Inserisci <username>: ");
    if(fscanf(stdin, "%63s", user) == EOF){
        fprintf(stdout, "\nErrore, impossibile leggere i dati\n");
        exit(EXIT_FAILURE);
    };
    fprintf(stdout, "\n--> Inserisci <password>: ");
    get_pass(pass);

    /* Stampo a video le informazioni immesse */
    fprintf(stdout, "\n\nHost: %s\nUser: %s\nPass: %s\n\n", host,user,pass);

    /* Azzero il buffer della password e libero la memoria occupata */
    memset(pass,0,(strlen(pass)+1));
    free(host);
    free(user);
    free(pass);

    return EXIT_SUCCESS;
}

void get_pass(char *p){
    /* Grazie a termios.h posso disabilitare l'echoing del terminale (password nascosta) */
    struct termios term, term_orig;
    tcgetattr(STDIN_FILENO, &term);
        term_orig = term;
        term.c_lflag &= ~ECHO;
        tcsetattr(STDIN_FILENO, TCSANOW, &term);
        /* Leggo la password e controllo il 'return code' di fscanf */
        if(fscanf(stdin, "%63s", p) == EOF){
        fprintf(stdout, "\nErrore, impossibile leggere i dati\n");
        tcsetattr(STDIN_FILENO, TCSANOW, &term_orig);
        exit(EXIT_FAILURE);
    };
        /* Reimposto il terminale allo stato originale */
        tcsetattr(STDIN_FILENO, TCSANOW, &term_orig);
}

I would like to know if it is correct that the function get_pass haven’t a return code?

In this function I read the password with fscanf and then I think that I have to return it to the main program…but:

  1. I don’t know how (with return p; I got a warning)
  2. It works also without return p; so I think that it is all ok…but I’m not so sure…

I don’t understand how return work with functions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:06:27+00:00Added an answer on June 3, 2026 at 4:06 am
    int main() 
    {
       char * password = NULL;
    
       get_pass(&password); //that is how you want to pass pointer to pointer
    
    }
    
    void get_pass(char **password) 
    {
    
    //1. get password using scanf from stdin or whatever way you want. 
    //2. assign it to *password 
    //3. no need to return anything
    
    }
    

    Remember, you need to handle memory allocation for password string. Let’s say you want to fix the password size to MAX_PASS_SIZE, then allocate that much memory either in main() or in get_pass so that you don’t corrupt your stack memory. The above snippet I wrote just shows how to populate value into password, which probably is your main question, i.e. pass a pointer to pointer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
I'm executing this code: void update_process(PROCSP * process){ int state; printf(process.pid = %d\n, process->pid);
With this code: private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { const int TICKETSOURCE_COLUMN =
This is driving me crazy: I have function void gst_init(int *argc, char **argv[]); in
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
Now i ve got this code: -(void)getContacts{ ABAddressBookRef currentAddressBook = ABAddressBookCreate(); if (currentAddressBook) {
Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
I have this code private void writeReport(IReport report, string reportName) { string reportString =
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.