User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Sep 2006
Posts: 8
Reputation: aaholland is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aaholland's Avatar
aaholland aaholland is offline Offline
Newbie Poster

Class Project

  #1  
Sep 7th, 2006
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Class Project

  #2  
Sep 7th, 2006
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?
Last edited by Ancient Dragon : Sep 7th, 2006 at 9:21 am.
Reply With Quote  
Join Date: Sep 2006
Posts: 8
Reputation: aaholland is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aaholland's Avatar
aaholland aaholland is offline Offline
Newbie Poster

Re: Class Project

  #3  
Sep 7th, 2006
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.

Originally Posted by Ancient Dragon View Post
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?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Class Project

  #4  
Sep 7th, 2006
>>Are you allowed to use non-ansi standard functions?

You didn't answer that question. If not then you may not get any credit at all. Of course if your class is studying curses then the question is moot.
Last edited by Ancient Dragon : Sep 7th, 2006 at 9:55 am.
Reply With Quote  
Join Date: Jul 2005
Posts: 1,098
Reputation: Lerner is a jewel in the rough Lerner is a jewel in the rough Lerner is a jewel in the rough Lerner is a jewel in the rough 
Rep Power: 9
Solved Threads: 142
Lerner Lerner is offline Offline
Veteran Poster

Re: Class Project

  #5  
Sep 7th, 2006
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.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Class Project

  #6  
Sep 7th, 2006
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.
Reply With Quote  
Join Date: Sep 2006
Posts: 8
Reputation: aaholland is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aaholland's Avatar
aaholland aaholland is offline Offline
Newbie Poster

Re: Class Project

  #7  
Sep 9th, 2006
Thanks for all the help I got a 97% on the project.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,806
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 338
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Class Project

  #8  
Sep 10th, 2006
Originally Posted by aaholland View Post
Thanks for all the help I got a 97% on the project.


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."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC