ive been trying to return a sorted array elements but its only returning the half of the array. any ideas why?
ive been trying to return a sorted array elements but its only returning the half of the array. any ideas why?
Post your code.
Anything else would be wild speculation on our part.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
bacically im trying to shift chars in an array inside a function..
If I call this function.. Im passing in a value(int) of how many shifts i want to do.Code:char *shifter(int numOfShifts) { char arr[] = "abcdefghijklmnopqrstuvwxyz"; ... shifting ... cout << arr << endl; return arr;
in return arr, its only returning halfo of the alphabets. but when printed in cout << arr << endl; the it prints out the whole alphabet
You're returning a pointer to a local variable!
So when the variable goes out of scope, the pointer is then pointing at non-existant data (well data you don't own anyway).
It's C++, so perhaps start with
std::string shifter(int numOfShifts)
There are several ways to solve it in a 'C' way, but none are as simple and elegant as the C++ std::string approach.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i have similar question
i have
now how can i return this array for using in another function??Code:???make_data_list_from_files() { char g; int n=count_member(); user_data pointer[n];//user_data is a class std::fstream file1; std::string map="%s/%s.dat"; std::string file1_str= string_print(map,R.c_str(),"Fname"); file1.open (file1_str.c_str(), std::fstream::in | std::fstream::app); std::string tmp; int i=0,p_num=0; while(!file1.eof()) { g=file1.get(); tmp.resize(i+1); tmp[i]=g; i++; if(g=='|') { tmp.resize(i-1); pointer[p_num].F_name(tmp); i=0; tmp.resize(0); p_num++; } } return what?? }
Last edited by king_zart; 12-09-2012 at 01:35 PM.
Use an std::vector, and return that.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.