In borland do I need to use the command line? Or can I get an IDE? And with strings, is that the only way to compare chars? Thx?:confused: :D
Printable View
In borland do I need to use the command line? Or can I get an IDE? And with strings, is that the only way to compare chars? Thx?:confused: :D
How do you mean you need strings to compare chars?
Thats bull
I know I can compare single chars but how do I compare an array of chars. Example:
char a[50]="greenhouse";
char b;
cout << "Enter greenhouse \n";
cin >> b;
if (b==a)
{
cout << "very good \n";
}
else
{
cout << "wrong \n";
}
.... // other stuff:mad:
Try....
In cstringCode:if(strcmp(compare this, and this))
{
//
}
You'll want to read up on the standard string functions. For example "strcmp" is used to compare (case sensitive) for exact string matches.
strcmp( astring, bstring );
Quzah.
Explain more or give me a site I can go to. (though I still think strings are easier!)
What would be the upside of using char over string?:confused:
You can manipulate strings more, and you can have whitespace in strings.Quote:
Originally posted by Stan100
What would be the upside of using char over string?:confused:
Oh, and I think strcmp returns false if the strings match, so maybe you'd want to use the ! operator
The free Borland compiler is command line only.
[\EDIT]
Of course, you can write a DOS batch file and click on it to compile. I've done that when writing long programs and I've gotten tired of typing the same command line over and over.
Some editors can invoke compilers too, but I've never used that feature.
[EDIT\]
I like strings, but why would I use chars instead?:D
I read your question wrong :D You can output chars more easily, and in some situations it is just unnecessary to use strings.
By way of information, a 'string' is a char array. Specialized, meaning more functional, but it's still a char array.
Research the member functions of the 'string' class (basic_string) to see what all is available to you. I'd venture to say that the majority of the members of this Board have never, nor will ever, make use of the full functionality that the 'string' class affords you.
We're weaned on traditional char arrays and are led, erroneously, to feel that using strings is akin to "cheating".
I can see this attitude in an academic setting where some value can be placed on learning the foundations of the language, but , beyond that..."Prefer string operations to C-style string functions." Bjarne Stroustrup
Now, before I get jumped all over and beaten badly - which I would look upon with disdain - there may, certainly, be situations where using chars may be preferred over strings. Can't think of any, at this moment, but... :)
-Skipper