Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,480 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,708 people online right now. Registration is fast and FREE... Join Now!




array

 
Reply to this topicStart new topic

array, why when i accept a string the while loop does not see the problem

lenoy
5 Mar, 2008 - 01:00 AM
Post #1

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 11

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

#define MAX 10

//#include <
//#include <
//#include <

void menu(void);
void code_Change();

int main()
{
char logId[MAX];
char codeChange[MAX]={1};//this line is a temporary intializer.


printf("Welcome to SouthCoast Serenity Inn database.\n");
printf("Please Enter Security Identification code to log in.\n");
gets(logId);

while(logId!=0)
{
if(logId==codeChange)
{
printf("Password verification correct.\n");
menu();
}
else

printf("Please re-enter password.\n");
gets(logId);

}
system("pause");
return 0;


}


void menu(void)
{
printf("please enter option\n");

}
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Array
5 Mar, 2008 - 01:23 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
can u elaborate more on your problem in the title.

and please use code.gif
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Array
5 Mar, 2008 - 01:34 AM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
CODE

gets(logId);

while(logId!=0)

You declare it as a char, you gather it with gets... but then you test against an integer...?
User is online!Profile CardPM
+Quote Post

captainhampton
RE: Array
5 Mar, 2008 - 06:52 AM
Post #4

Jawsome++;
Group Icon

Joined: 17 Oct, 2007
Posts: 518



Thanked: 2 times
Dream Kudos: 825
My Contributions
Are you trying to read in a default password to codechange for verification on whether or not the login id was correct? If so you must as no2pencil said be sure to stay consistent with you char array and what value would be valid as to when you would log in. A bit more elaboration and keeping your code between the "code" brackets would be helpful as such
cpp

example

User is offlineProfile CardPM
+Quote Post

lenoy
RE: Array
5 Mar, 2008 - 08:06 AM
Post #5

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 11

QUOTE(lenoy @ 5 Mar, 2008 - 02:00 AM) *

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

#define MAX 10

//#include <
//#include <
//#include <

void menu(void);
void code_Change();

int main()
{
char logId[MAX];
char codeChange[MAX]={1};//this line is a temporary intializer.


printf("Welcome to SouthCoast Serenity Inn database.\n");
printf("Please Enter Security Identification code to log in.\n");
gets(logId);

while(logId[MAX]!=0)
{
if(logId==codeChange)
{
printf("Password verification correct.\n");
menu();
}
else

printf("Please re-enter password.\n");
gets(logId);

}
system("pause");
return 0;


}


void menu(void)
{
printf("please enter option\n");

}



QUOTE(no2pencil @ 5 Mar, 2008 - 02:34 AM) *

CODE

gets(logId);

while(logId!=0)

You declare it as a char, you gather it with gets... but then you test against an integer...?






sholud i change logId to logId[MAX] ......how do i change logId to a character
User is offlineProfile CardPM
+Quote Post

captainhampton
RE: Array
5 Mar, 2008 - 10:56 AM
Post #6

Jawsome++;
Group Icon

Joined: 17 Oct, 2007
Posts: 518



Thanked: 2 times
Dream Kudos: 825
My Contributions
Well you just need to stay consistent, you declare loginID as a character array, and then after use the while loop to prompt as long as it is not equal to 0. What you could do is have the logID be an array of ints so long as such the ID does not contain a 0 in it. Or you could use a negative sentinel value for the user to enter when done as such:

cpp


int logID[MAX];

while ( logID != -1 )
.......

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 06:50PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month