corr[8]="pizzaboy";  error-- cannot convert char* to char

corr[]="pizzaboy";  error--  char has zero values

corr[0]="p"
corr[1]="i"
corr[2]="z" ----- syntax error

corr[8]='pizzaboy' ------- char const can have 2 chars

Is there any way to input:'( :'( :'( :'( :'(

Recommended Answers

All 50 Replies

How about posting actual code so we know what advice to give you. :icon_rolleyes:

>corr[8]="pizzaboy"; error-- cannot convert char* to char
Presumably corr is declared as char corr[N]; , which means that corr[8] has type char, not char*.

>corr[]="pizzaboy"; error-- char has zero values
Presumably this isn't a declaration.

>corr[2]="z" ----- syntax error
Presumably corr is declared as char corr[N]; , which means that corr has type char, not char*. You specify a character literal with single quotes.

>corr[8]='pizzaboy' ------- char const can have 2 chars
You seem to be making every mistake humanly possible while actively avoiding the correct solution...

int password(char usr_name[], char pwd[])
{
int j=0,k=0,i=0,m=0,n=0;
char corr[9],po[7];
corr[8] = "pizzaboy";

     for(i=0;usr_name[i]!='\0';i++)
       {
	if (usr_name[i]== corr[i])
	n=1;
       else
	n=0;
       }
	po[] == "qwerty";
	for(j=0;pwd[j]!='\0';j++)
	{
	if (pwd[j]== po[j])
	m=1;
	else
	m=0;
	}
	if (m==1 && n==1)
	   k=1;
	   else
	   k=0;
	  return (k);
	   }

btw what is char* ??

corr[8]="pizzaboy"; error-- cannot convert char* to char

That obvious. You're trying to put 9 chars in 1 char, so the compiler gives you an error

corr[]="pizzaboy"; error-- char has zero values

True. Replace it with char corr[]="pizzaboy";

corr[0]="p"
corr[1]="i"
corr[2]="z" ----- syntax error
[/quote]

If you asssign a single char to a char you need to use single quotes (and semicolons): corr[0]='p';

corr[8]='pizzaboy' ------- char const can have 2 chars

That's just silly :)


[edit] too slow, sorry about the double post Narue[/edit]

btw what is char*

A pointer to a char.

char corr[];
corr[]="passowrd";

error -- corr has unknown size or zero.

I am stuck with this error for 2-3 hrs now :'(

Did you actualy read anything I wrote?

Replace it with char corr[]="pizzaboy";

YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

My code is working now thanx :)

plz carify 1 more doubt sorry I have 2 submit my porj. tomoro.


how do I include the fn. ?

#include"FUNCTION.cpp" error-- cannot include file.

So DOES the file exist? In what file did you write the function? Show some code please.

#include<iostream.h>
#include<conio.h>
#include"FUNCTION.cpp"
void main()
  {
   clrscr();
   char ur,pass; int y;
   cout<<"Enter username and enter pasword"<<endl;
   gets(ur);
   cout<<"Enter password"<<endl;
   gets(pass);
   y=password(ur,pass);
   if(y==1)
   cout<<"Enter please"<<endl;
   if(y==0)
   cout<<"WRONG PASSWORD OR USERNAME"<<endl;
   else
   cout<<"Unknown error"<<endl;
   getch();
}

You didn't answer my question. IS the function you wrote in FUNCTION.cpp? If so: is FUNCTION.cpp in the same directory as main.cpp?

a few other points which will help your grade:

- it's int main() not void main()
- clrscr() might work fine with your old turbo C compiler, but it is not standard C
- gets() is a very dangerous thing to use
- use getchar() instead of getch()

no FUNCTION. is in my proj. folder.

and I am getting some weired errors such as
type mismatch in '__s' and and many other shit errors.
getch() in end is not for input itz for freezing the screen :)

Don't let my critisism demotivate you. A few more problems to solve and you're done :)
I'm signing off in about 10 min. But there are a lot of people here who are willing to help you, and most of them are more skilled then me ;)


[edit] you've changed your post...

>forget it I am having too much errors .....I quit of the proj.
If you can't handle the errors in that tiny program, I guess programming wasn't for you.

>sorry fr inconv. caused.
Not everyone is fluent enough in English to decipher this. Please use complete words and grammar as correct as you can manage.

[edit]
Replacing your entire post with something different is extremely rude.
[/edit]

sorry

no FUNCTION. is in my proj. folder.

and I am getting some weired errors such as
type mismatch in '__s' and and many other shit errors.
getch() in end is not for input itz for freezing the screen :)

Well put FUNCTION.cpp in you project folder, if that is the file where you put you function in.

I know what getch() is for. I still recommend you use getchar();

I put it in the main cpp folder and project and now still itz unable to open ?

I'm losing track with all your threads. Could you post ALL the code you have here and tell us which code is in which file and directory?

ok

Question.

wap to let a hotel manager login and input the menu using function.
funct 1->> Enter password.
funct 2->> Menu in a 2D array and price in a 1D array.

WAP to let a user acess his bill from the same prog. by echoing the price inputed by the manager.

LOGIN FUNCTION

int password(char usr_name[], char pwd[])
{
int j=0,k=0,i=0,m=0,n=0;
char corr[9],po[7];
corr[8] = "pizzaboy";

     for(i=0;usr_name[i]!='\0';i++)
       {
    if (usr_name[i]== corr[i])
    n=1;
       else
    n=0;
       }
    po[] == "qwerty";
    for(j=0;pwd[j]!='\0';j++)
    {
    if (pwd[j]== po[j])
    m=1;
    else
    m=0;
    }
    if (m==1 && n==1)
       k=1;
       else
       k=0;
      return (k);
       }

----------------------------------------------------------------------------

FUNCTION 2 MENU
OUTPUT SCREEN REQ. BY QUESTION (dots are spaces)

               ..........................................Hotel Name.......................................
  ...................................[U]Hungry Kya ??[/U] dunno how to underline..................

ITEM  ......................................................................................     PRICE

1)Burger   ......................................................................................    25
2)Pizza     ......................................................................................    50
3)Patty     ......................................................................................   and blah!!
Blah! Blah!

Code:

void Menu (char list[5][20], float price[5]);
{
int x=0
// x is the number of items.
for (i=0, i<=x ; i++)
 {

CLUELESS!!

---------------------------------------------------------------------------------------------

PROGRAM TO CALL FUNCTIONS

#include<iostream.h>
#include<conio.h>
#include"FUNCTION.cpp"
void main()
  {
   clrscr();
   char ur,pass; int y;
   cout<<"Enter username and enter pasword"<<endl;
   gets(ur);
   cout<<"Enter password"<<endl;
   gets(pass);
   y=password(ur,pass);
   if(y==1)
   cout<<"Enter please"<<endl;
   if(y==0)
   cout<<"WRONG PASSWORD OR USERNAME"<<endl;
   else
   cout<<"Unknown error"<<endl;
   getch();
} 

INCOMPLETE

--------------------------------------------------------------------------------------------------

I meant all the code, as in C++ code. Not your assignment

[edit] aha there it is.
Now please tell us which code is in which file?

I have all the codes made by me too.

[EDIT]All in the same folder "All assingments"

One of your big big problems is code style -- it is absolutely horrible. Here is an example of a better coding style and is a lot easier to read.

int password(char usr_name[], char pwd[])
{
    int j=0,k=0,i=0,m=0,n=0;
    char corr[9],po[7];
    corr[8] = "pizzaboy";

    for(i=0;usr_name[i]!='\0';i++)
    {
        if (usr_name[i]== corr[i])
            n=1;
        else
            n=0;
    }
    po[] == "qwerty";
    for(j=0;pwd[j]!='\0';j++)
    {
        if (pwd[j]== po[j])
            m=1;
        else
            m=0;
    }
    if (m==1 && n==1)
        k=1;
    else
        k=0;
    return (k);
}

Notice that line 14 of the above code is an error. I don't know what you are attempting to do there.

>>#include"FUNCTION.cpp"
NEVER EVER do that. When there are two or more *.cpp or *.c files then they should be compiled separately and linked together with the linker.

>> gets(ur);
NEVER EVER for any reason use gets() function because it can crash your program by copying more characters from the keyboard buffer into the input buffer (ur in the above case) than the input buffer can hold. That is called buffer overrun and gets() will just scribble all over memory. To correct this, use fgets() instead, like this: fgets(ur, sizeof(ur), stdin); fgets() too has a small problem: it appends the '\n' (the Enter key) to the end of the string, so your program has to strip it off. That's one big reason not to use C functions in a c++ function because the C++ iostream class doesn't do that.

fgets(ur, sizeof(ur), stdin);
if( ur[strlen(ur)-1] == '\n')
    ur[strlen(ur)-1] = 0;

at 14 Im trying to enter the string to be stored in array po[].

>>they should be compiled separately and linked together with the linker.

both the fuctions are compiled seperatly !!

How do I link them with the main prog. is my porblem.

at 14 Im trying to enter the string to be stored in array po[].

Your age has nothing to do with the problem. use strcpy() to copy one string to another strcpy( po, "pizzaboy" ); , assuming po is a character array large enough to hold the string.

>>they should be compiled separately and linked together with the linker.

both the fuctions are compiled seperatly !!

How do I link them with the main prog. is my porblem.

Depends on the compiler. Looks like you might be using Turbo C++, is that right? If it is, then just add each *.cpp file to the project separately and the IDE will link them correctly. That is just a matter of learning how to use your compiler.

BTW: please re-read my previous post because I added some more comments.

Yes I am using Tc++ v3.0 I suppose.

fgets is peety clumsy can I try using getche(); ?

[EDIT]Not my age 14 is the line number btw my age is 15. And strcpy is is good idea indeed ....btw po stores the correct pass and pwd is the one entered by the user. Also if I use strcpy instead of the loop won't the junk chars create prob. ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.