| | |
Return Array from C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#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.
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]
[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.
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.
> 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?
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?
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Popup Menu displays as very thin box
- Next Thread: Quicksort problems
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






