Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2008, 12:08 AM   #11
misho
Newbie
 
Join Date: Apr 2008
Posts: 10
Rep Power: 0 misho is on a distinguished road
Re: Got stuck while making a program,help would be appreciated

Here's a more pointer-based approach:
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. char a[1000];
  6. cin.getline(a, 1000);
  7. for(char* c = a; *c != '\0'; c++)
  8. *c != 'z' && *c != 'Z' ? ++*c : *c-=25;
  9. cout<<a<<endl;
  10. }

Or, if you prefer to use strings:
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. string s;
  7. getline(cin, s);
  8. for(char * c = (char*)s.data(); *c != '\0'; c++)
  9. *c != 'z' && *c != 'Z' ? ++*c : *c -= 25;
  10. cout<<s<<endl;
  11. }

I don't know if you've looked into them already, but if you're truly interested in learning C/C++, you'd have to learn about pointers sooner or later (also, your code tends to get shorter if you use them properly).

EDIT: I figured I should probably show you a version without pointers for comparison
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. string s;
  7. getline(cin, s);
  8. for(int i = 0; i<s.length(); i++)
  9. s[i] != 'z' && s[i] != 'Z' ? ++s[i] : s[i] -= 25;
  10. cout<<s<<endl;
  11. }

Last edited by misho; Apr 17th, 2008 at 12:38 AM. Reason: clarification
misho is offline   Reply With Quote
Old Apr 17th, 2008, 6:10 AM   #12
Marijan
Newbie
 
Join Date: Feb 2008
Posts: 15
Rep Power: 0 Marijan is on a distinguished road
Re: Got stuck while making a program,help would be appreciated

Thanks,just in time i started working with pointers
Marijan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. I got a problem in making Java games .. bratsercom Java 11 Oct 1st, 2007 2:31 PM
C++ Getting stuck within a loop. n3o_X C++ 5 Aug 29th, 2007 2:03 PM
Tutorials for making a P2P program? Palladio C++ 3 Nov 26th, 2005 3:51 AM
Multiple http-requests are stuck MereMortal C++ 0 May 4th, 2005 3:08 AM
Making a Note Adder/ Editor/ Deleter/ Viewer thingy brokenhope C++ 19 Apr 29th, 2005 1:30 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC