Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2005, 6:30 PM   #11
deathseeker25
Programmer
 
Join Date: May 2005
Posts: 48
Rep Power: 0 deathseeker25 is on a distinguished road
Quote:
Originally Posted by jim mcnamara
if this is a unix box try:
#include <unistd.h>
int main()
{
     char *pass=NULL;
     pass=getpass("Enter password");
     return 0;
}
In the compiler error log this is what appears:

9 C:\C projects\password maker2.cpp `getpass' undeclared (first use this function)

Please help me because i really want to use thsi little script for a personal program...
deathseeker25 is offline   Reply With Quote
Old Jun 29th, 2005, 6:45 PM   #12
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Show YOUR code, not Jim's clip. You have to have unistd.h available for inclusion as well as correct spellings and definitions
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 29th, 2005, 7:42 PM   #13
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
Originally Posted by DaWei
Why 7? He says in the prompt that the password is 10 characters, maximum.
The array size is 10.
so the max. subscript is 9.
1 char is reserved for null terminator.
so the count variable should not go beyond 8.
if(count>7) precisely specifies this.

I should have made this clear earlier. But i thought it was straight-forward .
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Jun 29th, 2005, 7:59 PM   #14
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You're right, of course. That'll teach me to read output and comments instead of declarations! :o
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 30th, 2005, 8:15 PM   #15
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by DaWei
You're right, of course. That'll teach me to read output and comments instead of declarations! :o
I also had to look twice for that, mainly because the code is not formatted (tabbed) while it is in code tags.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jul 3rd, 2005, 11:33 AM   #16
clearbit
Newbie
 
clearbit's Avatar
 
Join Date: Jun 2005
Location: far..far..away
Posts: 25
Rep Power: 0 clearbit is on a distinguished road
You should make the array have a constant 10.

#define MAX 10

char pass[MAX];
...

just a thought
clearbit is offline   Reply With Quote
Old Jul 8th, 2005, 2:46 AM   #17
chanti
Newbie
 
Join Date: Jul 2005
Location: HYDERABAD(INDIA)
Posts: 4
Rep Power: 0 chanti is on a distinguished road
Send a message via Yahoo to chanti
Hi NavNav,

I have made small changes in u r code. Try this one. It is working fine.


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

char pass[10];
int count=0;

int main(void)
{
printf("Enter new password (10 characters max):");

while ( (pass[count++]=getch()) != '\r')
{

if(count > 10)
{
for (count=0; count<10; count++)
{
pass[count] = '\0';
}
printf("\n\nYour password is too long, enter it again:");
count = 0;
continue;
}
else
{
if (pass[count-1] == '\b' && count==1)
{
count=0;
continue;
}
else
{
if (pass[count-1] == '\b')
{
printf("\b");
printf(" \b");
count -= 2;
}
else
{
printf("*");
}
}
}

}
puts("\n\nYour new password is:");puts(pass);
printf("\n");
system("pause");
return 0;
}


I u have any doubts, send mail to me.
chanti is offline   Reply With Quote
Old Jul 8th, 2005, 6:14 AM   #18
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
You can post in [code] tags. Which preserves indenting.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jul 12th, 2005, 11:10 AM   #19
chanti
Newbie
 
Join Date: Jul 2005
Location: HYDERABAD(INDIA)
Posts: 4
Rep Power: 0 chanti is on a distinguished road
Send a message via Yahoo to chanti
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

char pass[10];
int count=0;

int main(void)
{
printf("Enter new password (10 characters max):");

while ( (pass[count++]=getch()) != '\r')
{

if(count > 10)
{
for (count=0; count<10; count++)
{
pass[count] = '\0';
}
printf("\n\nYour password is too long, enter it again:");
count = 0;
continue;
}
else
{
if (pass[count-1] == '\b' && count==1)
{
count=0;
continue;
}
else
{
if (pass[count-1] == '\b')
{
printf("\b");
printf(" \b");
count -= 2;
}
else
{
printf("*");
}
}
}

}
puts("\n\nYour new password is:");puts(pass);
printf("\n");
system("pause");
return 0;
}


I have tested in VC++ editor. this is working fine..............
chanti is offline   Reply With Quote
Old Jul 12th, 2005, 11:22 AM   #20
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
Quote:
Originally Posted by nnxion
You can post in [code] tags. Which preserves indenting.
I thought maybe this needed to be repeated.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC