Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
2
of 2 vote

use curses.h or ncurses.h

#include <curses.h>
int main()
{
	initscr(); 
	char c;
	noecho(); 
	while((c = getch()) != '\n') {
		printw("*");
	}
	endwin(); 
	return 0;
}

compile:

gcc -lcurses a.c

- nz2324nz2324 October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Will try this one out... :)

- Shyam October 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This one doesn't work on a windows environment. Anyone got a code that runs on windows?

Thanks.

- Shyam October 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use printf("\r") in C - its called carriage return. This goes to the beginning of the current line on the command prompt instead of going to the beginning of new line.

- pankajb64 October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can maintain 2 strings, one string you will append real characters, in another string you will add *. so for display you can * string, for validation of password, you can use real string.
I may be not understanding the problem. you can give more details.

- RRR October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes,we can use 2 string but how will you replace the character typed in command line with second string characters.
Suppose when you typed 'P' it should be shown as '*'.can you give implementation.

- anuj.iiit2007 October 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

char c;
	std::string s;

	for ( ;(c = getch()) && c != 13  ; )
	{
		s.push_back(c);
		putch('*');
	}
	printf("\n%s to verify the logic...",s.c_str());

ofcourse 13 is value for \n

- howaboutthis October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is "std::string s;"?

I've been coding for a while but never seen a coding of this sort? Where can I find more info on this?

Thanks in advance.

- Shyam October 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That represents a c++ string class. :: is used as a scope resolution operator and string is a class in std namespace in c++

- vaibhav October 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

std::string s;
means standard namespace that "using namespce std", if u r not declared this in ur cpp current file then user has to standard form to delcare any variables.

- Jaya November 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <termios.h>
#include <unistd.h>

void echo( bool on = true )
  {
  struct termios settings;
  tcgetattr( STDIN_FILENO, &settings );
  settings.c_lflag = on
                   ? (settings.c_lflag |   ECHO )
                   : (settings.c_lflag & ~(ECHO));
  tcsetattr( STDIN_FILENO, TCSANOW, &settings );
  }

- NACHIKETA October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the function echo in linux will disable or enable the printing of characters entered entered by the user . This can be used to impement the password functon as in LINUX where the characters entered by the user are not visible.

- NACHIKETA October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# include<stdio.h>
# include<conio.h>
main()
{
	int i=0,j;
	char pass[23],c;
	printf("enter your password\n");
	while((c=getch())!=13)
	{
		pass[i++]=c;
		printf("*");
	}
	pass[i]='\0';
	printf("the password that you have entered is %s",pass);
	getch();
}

- Anonymous October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Instead of thinking in code think in words: you want to turn echoing off from a terminal or console. Echoing is a concept where input scanned from the keyboard is displayed on screen. You can turn this on (usually on by default) or turn it off. Under *nix based operating systems, curses is the usual choice for manipulating terminal properties.

- Anonymous October 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

write a c program to display

abcdedcba
abc cba
ab ba
a a

- Anonymous February 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i want password code for linux gcc compiler

- sampath kumar July 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

plzzzzzzzz

- Anonymous November 05, 2019 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More