Jump to content
  • Advertisement
Sign in to follow this  
gaiger

I have a problem....

This topic is 4115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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??

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!