DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Return Array from C++ (http://www.daniweb.com/forums/thread5939.html)

egemen Mar 5th, 2007 12:01 pm
Re: Return Array from C++
 
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

string plainfirst;
string key;

char*  perkey(char astr[]){ // permutate key
// cout<<"deneme "<<astr;
char* ptr;
 for(int i = 0; i<strlen(astr); i++){
  *(ptr + i) = astr[i];
  *(ptr + i) = '\0';
}

return ptr;
}

void printArray(char* array)
{

    for (int i = 0; i <10; i++){
        cout << *(array+i) << " ";
    }
    cout << endl;
    cout << endl;
}

int main (){

char str[10];

cout<<"key: ";
cin.getline(str,10,'$');

char* e = perkey(str);



printArray(e);

return 0;
}


i couldn't returned array is writen, how can i solve this problem.

WaltP Mar 5th, 2007 3:56 pm
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?

alleycat429 Jun 10th, 2007 7:11 am
Re: Return Array from C++
 
Quote:

Originally Posted by WaltP (Post 325235)
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?!!

Ancient Dragon Jun 10th, 2007 9:08 am
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 :-O [/edit]

Ancient Dragon Jun 10th, 2007 9:18 am
Re: Return Array from C++
 
Quote:

Originally Posted by alleycat429 (Post 385853)
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 ?

Salem Jun 10th, 2007 9:37 am
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?

Ancient Dragon Jun 10th, 2007 10:48 am
Re: Return Array from C++
 
Quote:

Originally Posted by Salem (Post 385884)
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.


All times are GMT -4. The time now is 11:42 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC