Status
Not open for further replies.

prateek

Banned
Banned
266
2009
72
0
Please see this program

I am not getting the desired output :(

PHP:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
	clrscr();
	char pass[32], ch;
	printf("Enter Password : ");
	while(1)
	{
	ch=getch();
	if(ch=='q' || ch=='Q')
	break;
	putchar('*');
	}
	printf("\n\n Password is : %s",pass);
	printf("\n\n Displaying pass is diff way");
	for(int i=0; i<=32; i++)
	printf("%c",pass[i]);
	getch();
}

can anyone tell what's the problem

I am getting this output :(
[SLIDE]http://i44.tinypic.com/148q1jm.png[/SLIDE]
 
17 comments
Use this and it will work !

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char pass[32], ch;
printf("Enter Password : ");
while(1)
{
ch=getch();
if(ch=='q' || ch=='Q')
break;
putchar('*');
}
printf("\n\n Password is : %s",pass);
printf("\n\n Displaying pass is diff way");
for(int i=0; i<=32; i++)
printf("%c",pass);
clrscr();
getch();
}
 
It is Printing the garbage value of variable pass

It is Printing the garbage value of variable pass..if you want to save password in variable pass,you should use scanf rather printf ..


currently ,the variable pass has no value /garbage value..so it is printing garbage value
 
what attitude ??
in my last post
i asked for help and i saw ppl posting solutions in different functions ...
so this time i wrote no to use diff functions ..

u r taking in wrong way ..
 
thanks for your help Techking

our teacher is teaching us the these new functions
so we have to use this function ...
and 2morow is my exam can't ask teacher also for help :facepalm:


edit --

any solution for this
as we are learning password program and we have to use this functions only
 
what attitude ??
in my last post
i asked for help and i saw ppl posting solutions in different functions ...
so this time i wrote no to use diff functions ..

u r taking in wrong way ..

So do you look in anyway i did joke or something , you should say what you needed , and i didn't changed the functions just changed its position . Thats all .
 
so actually you wanna print the value of password in the screen ?

when the user inputs the values
the text is shown in astricks
one astrik for one character (this cannot be done using scanf function that is why i am using the purchar function and getch function )

and after storing the password in the array

quit entering password when Q or q is typed

then we have to display the password


the getch() function inputs the text from user without echoing ..
 
Last edited:
I modified the progoram

and now the output is somewhat working
but still not fully working

here is the new code

PHP:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
	clrscr();
	char pass[32], ch;
	printf("Enter Password : ");
	int j=0;
	while(1)
	{
	ch=getch();
	if(ch=='q' || ch=='Q')
	break;
	pass[j]=ch;
	putchar('*');
	j=j+1;
	}
	printf("\n\n Password is : %s",pass);
	printf("\n\n Displaying pass is diff way");
	for(int i=0; i<=32; i++)
	printf("%c",pass[i]);
	getch();
}


outout is [SLIDE]http://i44.tinypic.com/2jd26mg.png[/SLIDE]



typed prateek as password
 
Hello,

Program more simplified by me

there is only one last problem
why is the @ sign OR ANY OTHER GRABAGE VALUE comming at the end of the password ??

PHP:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
	clrscr();
	char pass[32], ch;
	printf("Enter Password : ");
	int j=0;
	while(1)
	{
	ch=getch();
	if(ch=='q' || ch=='Q')
	break;
	pass[j]=ch;
	putchar('*');
	j=j+1;
	}
	j=j+1;
	pass[j]='\0';
	printf("\n\n Password is : %s",pass);
	getch();
}



OUTPUT
[SLIDE]http://i42.tinypic.com/24qua7d.jpg[/SLIDE]
 
try this

// test.cpp : Defines the entry point for the console application.
//



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



void main()
{
int k=0,j=0;
char pass[32], ch=' ';
printf("Enter Password : ");

while(1)
{
ch = getch();
k=k+1;

if(ch=='q' || ch=='Q')
{
pass[j]='\0'; j=j+1; break;}
else if(((int)ch >32 && (int)ch <123 ) && (ch!='q' || ch!='Q'))
{
putchar('*');
pass[j]=ch;
j=j+1;
}


}
printf("\n\n Password is : %s",pass);
printf("\n\n Displaying pass is diff way ");

for(int i=0; i<j; i++)

printf("%c",pass);
getch();

}

//complied in Oracle studio Enterprise Edition
 
My sir also solved the problem

the working program is nw
PHP:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    clrscr();
    char pass[32], ch;
    printf("Enter Password : ");
    int j=0;
    while(1)
    {
    ch=getch();
    if(ch=='q' || ch=='Q')
    break;
    pass[j]=ch;
    putchar('*');
    j=j+1;
    }
    pass[j]='\0';
    printf("\n\n Password is : %s",pass);
    getch();
}
 
Status
Not open for further replies.
Back
Top