•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,371 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 1079 | Replies: 7
![]() |
I am writing a program for my college class :eek: It has to record a password, but it cant display it on the screen. It is a unix based enviroment. Does this look correct to you guys?
main()
{
int i;
char buffer[80];
initscr();
printw("Please enter a password => ");
refresh();
noecho();
while((buffer[i] = getch()) != '\n') i++;
printw("\nPassword is %s - press return to continue.",buffer);
refresh();
getch();
endwin(); } Last edited by WolfPack : Sep 7th, 2006 at 9:04 am.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation:
Rep Power: 36
Solved Threads: 867
I see the program must be using curses?? Are you allowed to use non-ansi standard functions?
>>Does this look correct to you guys
How it "looks" is unimportant. Does your program compile with 0 errors and does it work ok when you run and test it?
>>Does this look correct to you guys
How it "looks" is unimportant. Does your program compile with 0 errors and does it work ok when you run and test it?
Last edited by Ancient Dragon : Sep 7th, 2006 at 9:21 am.
Yes it compiles with 0 errors. I just wanted to make sure it was the correct way to do this so i can get full credit.
Yes it uses curses.
Yes it uses curses.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation:
Rep Power: 36
Solved Threads: 867
•
•
Join Date: Jul 2005
Posts: 1,098
Reputation:
Rep Power: 9
Solved Threads: 142
Not being familiar with whatever curses is I still have a couple concerns with the code as posted.
First, main() should be declared with a return type, just like any other function. That return type should be type int to be standard, though implementations of some compilers allow you to use void as a return type.
Second, C style strings are null terminated char arrays. To my knowledge, getch() doesn't automatically append a terminating null char to buffers like scanf() or >> or getline() will. Therefore I am concerned that the char array you call buffer is not truly a string, but instead remains a routine array of char, until you specifically add the null terminating char.
First, main() should be declared with a return type, just like any other function. That return type should be type int to be standard, though implementations of some compilers allow you to use void as a return type.
Second, C style strings are null terminated char arrays. To my knowledge, getch() doesn't automatically append a terminating null char to buffers like scanf() or >> or getline() will. Therefore I am concerned that the char array you call buffer is not truly a string, but instead remains a routine array of char, until you specifically add the null terminating char.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation:
Rep Power: 36
Solved Threads: 867
most programs that use passwords display an asterisk for each character typed. Your program probably should do that too, and it can be done within that while loop. If you look at the curses library you might find there it already a function that will do it for you. That loop also needs to check for buffer overflow, do not allow i to exceed the size of input buffer.
Last edited by Ancient Dragon : Sep 7th, 2006 at 12:47 pm.
Congratulations, just keep on putting effort in your work and the rewards will definately come back to you. And if you encounter any other problem just dont hesitate to ask it.
Hope you are enjoying your stay at the community.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
- Help with class project (Java)
- how can i call class in other project (C#)
- Boundary Class and Broker Class (Computer Science and Software Design)
Other Threads in the C Forum
- Previous Thread: Using Loops to calculate totals in C Program
- Next Thread: How to calculate total free memory



Linear Mode