"d.j." <> wrote in message
news

rEhc.317$...
> Mr. Holden could you please elaborate a lil more I don't understand.
> When you say they are different type what do you mean I assumed they
> were the same char. Why would I
>
> [snip] stname[0] == end
>
> when I am entering the students name, and what does the "*" and strcmp in
>
> [snip] char *end;
> strcmp(stname,end)==0
>
> mean.
>
> we just started c++ in class and I want to learn this to my full
> ability. So your help is greatly appreciated..
>
> Thanks in advance
>
> Dario
>
Dario, you need to read a book on C++. You don't understand what a type is,
or what a pointer is, or the difference between an element and an array of
elements, or simple string handling functions, these are big gaps in your
C++ knowledge.
Now I think that all Sam suggestions were wrong because he misunderstood
what you are trying to do. I suspect that what you want is for the user to
type in the string "end" and for your loop to break at that point. If that
is true then you don't understand the difference between a variable name and
a literal value either.
Here's a few brief answers to your questions, but really you need to get a
book and study. The gaps in your knowledge are a bit too big to answer in a
newsgroup post.
Nevertheless here's a very, very brief answer to some of the questions
you've raised.
1)
char end;
char stname[12];
end is a char variable, stname is an array of twelve chars, This means they
are of different type. char and array of char are not the same thing. The
type of an object of variable determines what you can do with that object of
variable. You can compare to chars for equality
char x;
char y;
....
if (x == y)
cout << "x and y are equal\n";
but you cannot compare an array for equality with anything. That's just the
rules of C++.
2)
char* end;
The * makes end a pointer to char (just like the [12] make stname an array
of char). I'm not going to try an explain pointers to you. Read a book if
you're interested, its one of the most difficult things that newbies have to
learn about.
3) strcmp is that way of comparing C style strings. C style strings are
represented as arrays of char. Remember that I said you cannot compare
arrays for equality. Well strcmp is what you do instead
char s1[12];
char s2[12];
....
if (strcmp(s1, s2) == 0)
cout << "s1 and s2 are equal\n";
You must include <string.h> to use strcmp.
4)
char end;
The above is a variable called end
"end"
The above is a value, the value is a C string consisting of the characters
'e', 'n', and 'd'.
char e;
The above is a variable called e.
'e'
The above is a character value (the letter e).
int two;
The above is a variable called two.
2
The above is the integer value two.
Values and variables are not the same thing. Just because you called a
variable end, does not mean it has the value end. A variable can have any
value, the value that you assign to it.
Now as I said, I strongly suspect that what you want to do is quit your loop
when the user types in the name "end". So you need to compare your the value
of your stname variable with the value "end". Like this
if (strcmp(stname, "end") == 0)
break;
You do not need a variable called end, you need a value.
HTH
john