On 3/4/07, GLOGIC 20 <[EMAIL PROTECTED]> wrote:
> im very new to programming also but i dont think you can assign a string the
> same as other languages
> im sure a million people will correct me on this but try this

The original poster was doing C++, so why give a C answer?

>
> //---------------------------------------------------------------------------
>
> #include <clx.h>
> #pragma hdrstop

What are these for?

> #include <iostream.h>
> #include <string.h>
> using namespace std;
> int main()
> { char name[20];// makes a char array of 20 elements
> cout << "Please enter your name ";
> gets(name);//gets accepts spaces and sends value to name array once carraige
> return is pressed

NO NO NO! gets() is one of the most dangerous function and should
never be used. It's considered deprecated... it does not check the
length of its input, so you can easily enter 100 characters even if
you only allocated 5 characters, resulting in a buffer overflow and a
very notorious method for breaching security.

> if (name == "John")
> {
> cout << "Your name is John ";
> }
> else
> {
> cout << "Your name is not John ";
> }
> system("pause");
> return 0;
> }
>
>
>
> >From: "len_kim" <[EMAIL PROTECTED]>
> >Reply-To: [email protected]
> >To: [email protected]
> >Subject: [c-prog] Evaluating Strings
> >Date: Sun, 04 Mar 2007 22:11:16 -0000
> >
> >Hello,
> >
> >I am brand new to programming and am currently attempting to learn
> >C++.
> >I am unable to get the below program to evaluate the string that is
> >entered for the name. Can someone tell me what I am doing wrong and
> >if it is even possible to run an "if" statement and make it evaluate
> >a string?
> >
> >#include <iostream>
> >#include <string>
> >using namespace std;
> >int main()
> >{ string name;
> >cout << "Please enter your name ";
> >cin >> name;
> >if (name == 'John')
> >cout << "Your name is John ";
> >else
> >cout << "Your name is not John ";
> >return 0;
> >}
> >
>
> _________________________________________________________________
> With tax season right around the corner, make sure to follow these few
> simple tips.
> http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=HMFebtagline
>
>
>
>
> To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
> Yahoo! Groups Links
>
>
>
>


-- 
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to