I have a problem....

Started by
10 comments, last by Zahlman 17 years, 1 month ago

#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 need to change this code that will not using strlen if i remove the strlen the reverse name will not appear.. can you help me with it??
Advertisement
Why do you need to remove strlen?
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.
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
Ring3 Circus - Diary of a programmer, journal of a hacker.
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?
Impliment your own strlen() (Just loop until you find the null terminator)

Is this homework?
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>
Comrade, Listen! The Glorious Commonwealth's first Airship has been compromised! Who is the saboteur? Who can be saved? Uncover what the passengers are hiding and write the grisly conclusion of its final hours in an open-ended, player-driven adventure. Dziekujemy! -- Karaski: What Goes Up...

This topic is closed to new replies.

Advertisement