#include<iostream.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
int x,y;
char name[20],lo[20],up[20],rev[20];
main()
{
cout<<"Enter your name:";
cin>>name;
y=strlen(name);
for(x=0;x<y;x++)
{
if(tolower(name[x]))
lo[x]=tolower(name[x]);
}
for(x=0;x<y;x++)
{
if(toupper(name[x]))
up[x]=toupper(name[x]);
}
for(x=0;x<20;x++)
rev[x]=name[y-x-1];
cout<<"\nLower case: "<<lo;
cout<<"\nUpper case is: "<<up;
cout<<"\nReverse is: "<<rev;
getch();
}
I have a problem....
Homework?
If your teacher told you not to use strlen, then maybe you should change the loop so that it stops when you encounter the terminator of the string ('\0').
There're many issues with your code, though.
If your teacher told you not to use strlen, then maybe you should change the loop so that it stops when you encounter the terminator of the string ('\0').
There're many issues with your code, though.
Im just curious with it... I want some unique ideas and to do with that i need to remove the strlen... Because someone in my classmate ideas is same in my code... Not good reason but the only way to resolve this thing is to solve this with help or without help...
If you need to find out the length of the string, then you need to find out the length of the string.
Any alternatives we propose would either require a fairly major rewrite, or an equivalent function (lstrlen? [wink]).
Admiral
Any alternatives we propose would either require a fairly major rewrite, or an equivalent function (lstrlen? [wink]).
Admiral
But my problem is not to use any string function unless the only way to find it out is to reverse the character of my code is using the string function then i will use it but not the strlen code...
0) We don't do homework here.
1) There are huge problems with what you are being taught. I strongly recommend you drop this course because it will not teach you anything properly.
1a) For example, there is really no such thing as iostream.h any more.
1b) Noone in the real world does string manipulation at this level without a really good reason.
1c) Reading into a buffer of constant size limits the size of strings (to the buffer size) for absolutely no good reason (because the new C++ standard library provides tools that get around that limit).
2) Do you know how strlen() works? If so, then the obvious thing would just be to implement it yourself, right?
1) There are huge problems with what you are being taught. I strongly recommend you drop this course because it will not teach you anything properly.
1a) For example, there is really no such thing as iostream.h any more.
1b) Noone in the real world does string manipulation at this level without a really good reason.
1c) Reading into a buffer of constant size limits the size of strings (to the buffer size) for absolutely no good reason (because the new C++ standard library provides tools that get around that limit).
2) Do you know how strlen() works? If so, then the obvious thing would just be to implement it yourself, right?
Nope this is not a homework actually my friend told me this problem... My friend is a genius in C++ and he told me if i create a program that will appear the uppercase, lowercase, and reverse without using strupr, strlwr, strrev and strlen thats all...
Educate yourself on the C ways of char arrays and the integer representations of ASCII characters and you can do it without ever including <string>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement