Click here to Skip to main content
15,893,968 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include<iostream.h>
#include<stdio.h>
#include<string.h>
void main()
{
char a[20];
cout<<"Please enter the required password"<<endl;
cin>>a;
if (a=="strike"){
cout<<"access Granted!"<<endl;
} 
gets(a);
}
Posted
Updated 1-Sep-15 1:41am
v2
Comments
CHill60 1-Sep-15 7:41am    
What happens when you run it? What were you expecting to happen?
Richard MacCutchan 1-Sep-15 7:45am    
What's wrong? The attempt to read into an array, the comparison of a pointer to a string ...
You need to go back to your study notes and review the chapter(s) that you have been working on.
Member 11950455 1-Sep-15 8:23am    
I expected access granted to display if strike was entered
Member 11950455 1-Sep-15 8:23am    
a... actually i'm a beginner in this topic
Member 11950455 1-Sep-15 8:24am    
please suggest me the correct programs!

1 solution

hi,
you already know about string header file so instead of using char pointers directly, its better to use the strings like this :

C++
#include<iostream>

int main()
{
std::string userInput;
std::cout<<"Please enter the required password"<<std::endl;
std::getline(std::cin,userInput);

std::string actualPassword = "strike";

if(userInput == actualPassword)
std::cout<<"access Granted!"<<std::endl;

return 0;
}


still find out on your own how char array is different from std::string.Google is your friend.
and as already mentioned in comments, try to better your understanding of the concepts.

hope this helps !!
 
Share this answer
 
v2
Comments
Member 11950455 2-Sep-15 8:03am    
Thank you very much!!! could u please do me one more favour, please tell me what does this std:: stand for?? I haven't been using int main(), i'm using void main ()!
chandanadhikari 2-Sep-15 9:44am    
hi,
first of all try to read about the basics of the language (i provided 2 links in my other comment)
Nobody is going to give you a crash course in C++ on codeproject. try to google out these things on your own and if you dont find anything useful then only post it here.
i'll give you some information but you have to search the web for more:
std is the standard namespace and when i want call a function defined within that namespace then its std::functionname. Now read/find out what is a namespace .
i used int main() as my compiler wont let me return void from main.
This might be confusing for a beginner. thats why take one step at a time and first learn the basics.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900