|
-
Nov 23rd, 2001, 03:39 PM
#1
Thread Starter
Addicted Member
uppercase
how do i change a string to all uppercase~?
To understand recursion, one must first understand the concept of recursion.
-
Nov 23rd, 2001, 03:43 PM
#2
Member
If you're still using the LVP deal:
Code:
#include <ctype.h>
#include <iostream.h>
#include "string.h"
int main()
{
String s = "tESt";
for (int i = 0; i < s.length(); i++)
{
s[i] = tolower(s[i]);
}
cout << s;
return 0;
}
-
Nov 23rd, 2001, 03:48 PM
#3
PowerPoster
I have not tested it but try this and there might be some errors:
PHP Code:
char mystr[50], mystr2[50];
cin>>mystr;
for(int i=1;i<=strlen(mystr);i++)
{
mystr2 = mystr2 + (char)((int)mystr[i] + 32);
}
cout<<mystr2;
-
Nov 23rd, 2001, 05:15 PM
#4
abdul: your program will probably work to make a string composed ONLY of lowercase alpha characters (a-z, nothing else). It won't work in any other case - that can be corrected by replacing the line in the for loop by toupper(...).
for Filburt's code: toupper, not tolower...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 23rd, 2001, 06:33 PM
#5
Thread Starter
Addicted Member
I'm not using string.h. I'm using string
To understand recursion, one must first understand the concept of recursion.
-
Nov 24th, 2001, 05:02 AM
#6
no matter, use filburts method slightly modified:
Code:
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "tESt";
for (int i = 0; i < s.length(); i++)
{
s[i] = tolower(s[i]);
}
cout << s;
return 0;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 24th, 2001, 06:10 PM
#7
Thread Starter
Addicted Member
thanks all of ye~! i"m making a silly hangman game to get used to C++, and well, i thought it would be appropriate to make the letters you enter non-case sensative =] I have one more question, though. How come when I link to conio.h, clrscr() and gotoxy() don't work, but when i link to conio.c, they do?
To understand recursion, one must first understand the concept of recursion.
-
Nov 24th, 2001, 08:38 PM
#8
Shouldn't you guys be using the _toupper function?
-
Nov 25th, 2001, 11:21 AM
#9
Thread Starter
Addicted Member
well, i am, but for my purposes - converting all the letters to one case to compare them without having to worry about case sensitivity - it could be either one. now someone tell me whats up with conio.h :[
To understand recursion, one must first understand the concept of recursion.
-
Nov 25th, 2001, 12:27 PM
#10
Member
This is not C++
Is this not that Vb you are coding with?
May you post this in the Forum for Visual Basic, you will have more sucess with the answere.
In C++ just write in a App with MFC:
varname.MakeUpper();
Cheers,
Myvar
-
Nov 25th, 2001, 01:22 PM
#11
Ahem...
Myvar: he is NOT coding VB, this is just his signature...
And he should NOT use MFC unless he knows both C++ and the API well.
Moose: what compiler do you use? Basically, you include header files (.h, .hh, .hpp, no extension) and link to modules (.c, .cpp), object files (.o, .obj) and libraries (.lib, .a). The extensions depend on what you do and on the compiler. clrscr() and gotoxy() are only borland...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 01:38 PM
#12
Thread Starter
Addicted Member
I use bloodshed. The only problem I'm haivng with C++ is it's hard to know how to use the header files ;p In school, I learned to use conio.h and clrscr(), gotoxy(), and also lvp\string.h and the functions that go with that. I thought every header file would be just like those, but I guess not. I'd like to know how to clear the screen with the compiler i'm using - bloodshed, but I think more importantly, I'd like to know how Im supposed to figure out how to use all the included header files.
Why can't C++ be nice and simple with everything built in like VB =D No, before 50 people jump all over me and think i'm serious about that, no, i'm sure it makes c++ more powerful in the end :P Anywayz, the syntax in C++ is really simple, it's just understanding how to use it with header files and the like that confuses me :[ So, what i want to know now is a website maybe? something that explains all this to me.
To understand recursion, one must first understand the concept of recursion.
-
Nov 25th, 2001, 02:25 PM
#13
The cross-browser method to clear the screen is system("cls"); (for DOS, for LINUX it would be "clear"). You need to include stdlib.h.
For the headers:
header files provide declarations of the functions in libraries and modules. They are included with the #include directive: use <filename> for headers that come with the compiler and "filename" for headers you wrote yourself.
I heard bout the lvp/ thing twice now, and it seems to be something very evil that has to do with a dumb compiler that some schools use.
There are two types of headers that come with compilers:
a) the standard headers. The functions inside are the same for all compilers all over the world. They are standardisized by ANSI. They include common headers such as stdlib.h, stdio.h, string.h and math.h. They also include the c++ standard headers, like iostream, fstream and string.
b) Compiler extensions: conio.h is the most common. They can contain different things and difer from compiler to compiler. DOS compilers (like DJGPP or older Borland and Microsoft compilers) will have completely different things in those than Windows compilers or Unix compilers. For example, conio.h for borland contains clrscr(), gotoxy() and such, while vc++6.0 conio.h contains outp() and inp().
Then there are libraries that have their own headers, like MFC or DirectX. You usually place them in their own directory and set the compilers standard search path to include those, so you can include them using <>.
Headers almost never contain real code, only declarations and constant definitions.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2001, 02:57 PM
#14
Member
Sorry
Sorry CornedBee I just wanted to help.
But may you tought that he MUST reinvent all Algorithms new. I understand thats important to understand whats behind MFC. But with C# the API is not used anymore, isnt it?
So why he had to know it?
But I see, you are the Teacher so keep teaching Coach.
Best Regards,
Myvar
-
Nov 25th, 2001, 03:11 PM
#15
Well, who uses C#? It's an evil M$ thing, and I will avoid it as long as possible. And nobody says you don't use API in C# (or does anybody? MS maybe?). It will be accessible, so people will use it sometimes. At least unless MS comes up with something far better than MFC. It is not bad, but it can make you sick sometimes.
And even if MS comes up with something better, he still should know how to use API IMO. Debugging MFC apps is a mess at best and hell at worst, so why should it be better with other libraries?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|