943,614 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 289337
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Mar 5th, 2007
0

Re: Return Array from C++

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string plainfirst;
  8. string key;
  9.  
  10. char* perkey(char astr[]){ // permutate key
  11. // cout<<"deneme "<<astr;
  12. char* ptr;
  13. for(int i = 0; i<strlen(astr); i++){
  14. *(ptr + i) = astr[i];
  15. *(ptr + i) = '\0';
  16. }
  17.  
  18. return ptr;
  19. }
  20.  
  21. void printArray(char* array)
  22. {
  23.  
  24. for (int i = 0; i <10; i++){
  25. cout << *(array+i) << " ";
  26. }
  27. cout << endl;
  28. cout << endl;
  29. }
  30.  
  31. int main (){
  32.  
  33. char str[10];
  34.  
  35. cout<<"key: ";
  36. cin.getline(str,10,'$');
  37.  
  38. char* e = perkey(str);
  39.  
  40.  
  41.  
  42. printArray(e);
  43.  
  44. return 0;
  45. }


i couldn't returned array is writen, how can i solve this problem.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
egemen is offline Offline
1 posts
since Mar 2007
Mar 5th, 2007
0

Re: Return Array from C++

Why are you hijacking a 3 year old thread? Can't you start a new thread with your new problem?
Last edited by WaltP; Mar 5th, 2007 at 3:56 pm.
Moderator
Reputation Points: 3278
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,717 posts
since May 2006
Jun 10th, 2007
0

Re: Return Array from C++

Click to Expand / Collapse  Quote originally posted by WaltP ...
Why are you hijacking a 3 year old thread? Can't you start a new thread with your new problem?


Gosh! when did Jack Nichalson change his name and become a C
programmer?!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alleycat429 is offline Offline
2 posts
since Jun 2007
Jun 10th, 2007
0

Re: Return Array from C++

function perkey() is using an unitilized pointer ptr Is the intent of that function to copy the contents of one string into another and return the pointer to the new string? Like strcpy() ? If so, then you need to call malloc() first to allocate memory for the new string.

[b]printArray[b] -- why are you using a loop to print each individual character when cout will print the entire string in one shot ?

And yes, you should have just started a new thread to ask your question.

[edit]Ok , ok so I failed to look at the datestamp of egemen's post -- three months old [/edit]
Last edited by Ancient Dragon; Jun 10th, 2007 at 9:16 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jun 10th, 2007
1

Re: Return Array from C++

Gosh! when did Jack Nichalson change his name and become a C
programmer?!!
And what makes you think Nichalson doesn't know how to program in C ?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jun 10th, 2007
0

Re: Return Array from C++

> Ok , ok so I failed to look at the datestamp of egemen's post -- three months old
Yeah, a 3 month bump, which in itself began as a bump of a 3 YEAR old thread.

I bet Jack knows how to spell his own name, regardless.

#include <topic.h>
Error - topic not found - entering thread wibble mode.

Can we close this now?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 10th, 2007
-1

Re: Return Array from C++

Click to Expand / Collapse  Quote originally posted by Salem ...
Can we close this now?
I don't think that's necessary -- it will probably die on its own. And DaniWeb rules don't permit closing a thread just because someone bumped it.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Popup Menu displays as very thin box
Next Thread in C++ Forum Timeline: Quicksort problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC