Return Array from C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 1
Reputation: egemen is an unknown quantity at this point 
Solved Threads: 0
egemen egemen is offline Offline
Newbie Poster

Re: Return Array from C++

 
0
  #11
Mar 5th, 2007
  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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Return Array from C++

 
0
  #12
Mar 5th, 2007
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: alleycat429 is an unknown quantity at this point 
Solved Threads: 0
alleycat429 alleycat429 is offline Offline
Newbie Poster

Re: Return Array from C++

 
0
  #13
Jun 10th, 2007
Originally Posted by WaltP View Post
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?!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Return Array from C++

 
0
  #14
Jun 10th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Return Array from C++

 
0
  #15
Jun 10th, 2007
Originally Posted by alleycat429 View Post
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 ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Return Array from C++

 
0
  #16
Jun 10th, 2007
> 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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Return Array from C++

 
0
  #17
Jun 10th, 2007
Originally Posted by Salem View Post
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC