<div dir="ltr">Hello all,<div><br></div><div>I am writing the function to take the password from the user using the termios (3). So far I have </div><div><br></div><div><div>int get_pass(unsigned char *pwd)</div><div>{</div>

<div>    struct termios oflags, nflags;</div><div>    char password[MAX_PASS_LEN];</div><div>    char pass2[MAX_PASS_LEN];</div><div><br></div><div>    /* disabling echo */</div><div>    tcgetattr(fileno(stdin), &amp;oflags);</div>

<div>    nflags = oflags;</div><div>    nflags.c_lflag &amp;= ~ECHO;</div><div>    nflags.c_lflag |= ECHONL;</div><div><br></div><div>    if (tcsetattr(fileno(stdin),  TCSANOW, &amp;nflags) != 0) {</div><div>    perror(&quot;tcsetattr&quot;);<br>

</div><div>    }</div><div><br></div><div>    printf(&quot;Password: &quot;);</div><div>    fgets(password, sizeof(password), stdin);</div><div>    password[strlen(password) - 1] = 0;</div><div><br></div><div>    while( strcmp(password,pass2) != 0){</div>

<div>        printf(&quot;Again : &quot;);</div><div>        fgets(pass2, sizeof(pass2), stdin);</div><div>        pass2[strlen(pass2) - 1] = 0;</div><div>    }</div><div><br></div><div>    memcpy(pwd,password,strlen(password));</div>

<div><br></div><div>    /* restore terminal */</div><div>    if (tcsetattr(fileno(stdin), TCSANOW, &amp;oflags) != 0) {</div><div>        perror(&quot;tcsetattr&quot;);</div><div>        return EXIT_FAILURE;</div><div>    }</div>

<div><br></div><div>    return 0;</div><div>}</div></div><div><br></div><div><br></div><div>This works fine when I run this by itself in a separate main function. However when I put this in with my other code I get some errors that I do not know how to handle and makes my program unstable.</div>

<div><br></div><div><br></div><div><div>pdudzins@rainman:~/cs631/hw5$ ./a.out -e &lt; test.txt &gt; out.txt</div><div>tcsetattr: Inappropriate ioctl for device</div></div><div><br></div><div>I am not sure how to appropriately handle the terminal using tcsetattr. Has anyone run into this problem?</div>
</div>