w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Returning char array from function
In this function: void GetFileContents(const char* FilePath, size_t& size, char* data){ file_mapping fm(FilePath, read_only); mapped_region region(fm, read_only); data = static_cast<char*>(region.get_address()); ... } fm and region are objects with automatic storage duration, lifetime of which ends when the execution goes out of scope. Using their internals after these objects are destructed yields undefined behavior. Another problem is that you are actually trying to change the pointer itself, meaning that your function should take char** dataPtr and you should call GetFileContents(FilePath, size, &data);. But since you are using C++, you should consider using std::string or since you're not working with null-terminated string, std::vector<char> mi

Categories : C++

returning character array from function
Try changing char *hold_array[] = get_array (); to char **hold_array = get_array (); Or (better still IHMO) to use malloc.

Categories : C

returning array from function to main in c++
Because you have a pointer, you don't need to dereference and use operator[] on the array. The pointer points to the first element in the array. If you want another element, you can just use the subscript operator, without worrying about dereference. Just do this: byteArray[j] = tempbitset.to_ulong(); //write to position j in the array.

Categories : C++

Function returning a pointer to an int array
int(*)[10] is a pointer to an array of 10 ints. int* is a pointer to int. These are different types. However, an array decays to a pointer to its first element, so you can do: int a[10]; int(*p)[10] = &a; int* q = a; // decay of int[10] to int* But not: q = p; p = q;

Categories : C++

Returning array from function with data from file
Firstly, this: file >> length; Student students[length]; Is non-standard extension. Length of array should be known at compile-time. Secondly, you're returning pointer to the memory that will be released once array goes out of scope. You should use std::vector instead: #include <vector> // ... std::vector<Student> getFromFile(string filename) { // ... std::vector<Student> students(length); Also you no longer need to pass length by reference, since std::vector has size member function.

Categories : C++

returning array of char pointers from a function (c++)
Returning objects allocated in the automatic storage (also known as "stack objects") from a function is undefined behavior. When you need to return an array in C, you have three options: Return an object allocated in the static storage area, Return an object allocated in the dynamic storage area, or Take a buffer and max size, and return the actual size of the array. The first option is rarely applicable, because it makes your function non-reentrant. The third option is widespread, but it has limitations: when you must return more data than fits into the buffer, the API needs to be called multiple times. This leaves us with option number two: use new to allocate the memory that you are returning, copy the data into it, and return the result to the caller. It is now caller's responsibi

Categories : C++

Symfony2 - Twig Function returning an array
This should happen because blogsList() returns an ArrayCollection, wich acts as an array, but it is not. According to this issue, you should just do: public function blogsList() { // ... return $blogs->toArray(); }

Categories : PHP

Returning type casted array to main function
You're getting a character then converting it to an int so you're only seeing the first 8 bytes. You need to convert to an int* first (but this is not a good thing to do H2CO3 will tell you why most likely) printf("Counts :%d ",((int*)ch)[1];

Categories : C

Function declaration error - returning an array of pointers
Returning an array is not something you can do in C++. Your function actually returns a pointer to the first element of ans, which is also bad news, since that array is declared on the stack and goes out of scope as soon as the function returns. The right thing to do would be to pick an appropriate data structure from the C++ standard library and use that. If for some reason you're set on fundamental types, you'll need to come up with a different solution - perhaps allocating the array dynamically inside your function and returning a pointer to it, for example.

Categories : C++

Function taking an array filled with structures, and returning a bigger array with the same structures
You can't reassign friends like that since it's not a pointer, it's an array. Even if you could, what you're doing isn't safe since GrowArray just creates a new array on the stack which will be destroyed when the function returns. You should either use new and delete to create and destroy the arrays (you can then then pass them around as pointers), or preferably, use std::vector which handles all this stuff for you.

Categories : C++

javascript 2D array iteration returning undefined function args
There were a few problems with your code: Several calls throughout the code refence undeclared variables row and col. The loop declares row as global (not an "error", but not good practice) The method call to deadCellsLiveOrDie is mistyped. The getNeighbors method does not make boundary checks, so you will run out of range. A (quickly) fixed version can be found here: http://jsfiddle.net/Eakcm/

Categories : Javascript

Exception while returning an empty Associative array from PLSQL function
A FOR cursor loop will: Open and parse the SELECT statement fetch each row close the statement when all rows have been fetched (or upon exciting the loop). Thus, it will never raise a NO_DATA_FOUND exception, even when no row is fetched. Therefore, your RETURN statement will never be reached, leading to the ORA-06503. You should instead write: FUNCTION GET_SAMPLE_MAP(ID IN NUMBER) RETURN ASSOC_ARR IS sample_map ASSOC_ARR; BEGIN FOR rec IN (SELECT LOC.STATE, LOC.POPULATION FROM LOCATIONS LOC) LOOP sample_map(rec.STATE) := rec.POPULATION; END LOOP; RETURN sample_map; END; Also worth mentioning that you should never catch an unexpected exception and silently ignore it. This leads to hard to diagnose bugs. You may think you're dealing with the exception, but in reality you're

Categories : SQL

Returning an array and storing into another array, creating a multidimensional array
My function generatePrice() returns an array, No it doesn't, it returns undefined. XHR is asynchronous, see How to return the response from an AJAX call?. priceArray = generatePrice(resultArr[ctr].symbol); I can't seem to store it in another array You didn't attempt to do so, you just stored the result of every call in the priceArray variable - instead of in a property of the array. Use priceArray[ctr] = generatePrice(resultArr[ctr].symbol); // or priceArray.push( generatePrice(resultArr[ctr].symbol) );

Categories : Javascript

Returning 'nil' from a Lua function in C vs returning 0 values
Yes, this is perfectly valid. If you're trying to request/assign more return values than there are (no matter whether you try to get one or ten), you'll get nil for the undefined ones (i.e. those not returned). function test1() return 5 end local a, b = test1() -- a = 5, b = nil function test2() return 1, 2 end local c, d, e = test2() -- c = 1, d = 2, e = nil function test3() end local f, g = test3() -- f = nil, g = nil You probably can't find it in Lua's source because it's no special case or anything. It's just Lua's generic way to handle return values. Update: The difference you've noticed when trying to print return values is the fact that this is not just an assignment. Of course there is a slight difference between returning nil and returning nothing at all - and it

Categories : C

Returning value (or nothing) for outer function from inner function of nested functions in Java
The method runOnUiThread accepts a Runnable argument. We can assume it uses its run() method somewhere. For example, if the method was public void runOnUiThread(Runnable runnable) { // do a bunch of stuff // some more logic runnable.run(); // more logic return; } You can't force a return of the calling method (runOnUiThread()) from the called method (run()). You can however throw an Exception within the called method that will stop all execution, but you won't necessarily know where that gets caught.

Categories : Java

Specializing class for generic function returning pointer to function
I believe this will work if you specialize it as: template<typename FpResultType, typename FpArg1, typename Arg1, typename Arg2> A<ResultType (*(Arg1, Arg2))(FpArg1)> {...}; I tested with the following code, which compiles successfully (using Clang): template<typename T> class A; template<typename FnRetT, typename FnArgT, typename Arg1, typename Arg2> class A<FnRetT (*(Arg1, Arg2))(FnArgT)> { public: typedef FnRetT fn_ret_t; }; float foo(float a) { return a; } float (*getfn(int arg1, int arg2))(float) { return foo; } int main(int argc, const char * argv[]) { typedef A<decltype(getfn)>::fn_ret_t ret_ty; return 0; } Note that the syntax used to match the function type matches the declaration of getfn.

Categories : C++

How to solve returning an array into an empty array Java
if (ship[z].GetLocation() != 0) ship[z] is empty (null), so that's why you get the error. You need to fill yout ship array first. The important thing is: ship array stores references not objects, so that's why you need to fill it first. So Ship[] ship = new Ship[10] stores 10 Ship references (which starts as null), the actual Ship objects you need to assign by yourself.

Categories : Java

$_POST is returning just 'Array' as string and i am posting an Array
I'm pretty sure that <input type="checkbox" name="om[1]" value="10"> is not the same as $_POST['om'][1] The one in the form is an array with a string-type index "1", while in the $_POST var you're accessing the first element of $_POST['om']. So you'll either have to use something else than integers in the HTML form or access the values by using $_POST['om']['1'].

Categories : PHP

Use tuple-returning Python function in another function call
Try this: bar(np.array([7,8]), *fu()) (unpack the tuple returned by fu())

Categories : Python

What does "error: ’myfn’ declared as function returning a function" mean?
You are allowed to return a function pointer, and the correct syntax looks like this: void (*myfn())(int) { } Complete example: #include <cstdio> void retfn(int) { printf( "retfn " ); } void (*callfn())(int) { printf( "callfn " ); return retfn; } int main() { callfn()(1); // Get back retfn and call it immediately } Which compiles and runs like this: $ g++ myfn.cpp && ./a.out callfn retfn If anyone has a good explanation for why g++'s error message suggests this is not possible, I'd be interested to hear it.

Categories : C++

Returning Entire Sub-Array (Containing Maximum Value) From Array
function max_dist($array) { $maxIndex = 0; $index = 0; $maxValue = $array[0]['distance']; foreach( $array as $i){ if($i['distance'] > $maxValue){ $maxValue = $i['distance']; $maxIndex = $index; } $index++; } return $array[$maxIndex]; } $jump = max(array_map("max_dist", $jumps)));

Categories : PHP

Why is this syntax used in Javascript (returning a function from a function)
In this case it would appear to be a function that's used to generate setter/getter functions for values. Without seeing more context to where this is being used, one can only guess why it's done like this. However from the looks of it, I'd imagine it's being used to make it easier to generate dynamic objects with certain behaviors (eg. getting/setting values with certain validations). Comparing to your alternative, it probably wouldn't even work like that considering the returned function uses the this keyword. Most likely it gets assigned into an object, thus this will refer to the object. As pointed out in the comments it is essentially currying, but it's also possible the data used to generate the function is not available to pass as a parameter at the later stage where the generat

Categories : Javascript

new to javascript, trying to understand function returning a function
function dostuff() { return function () {console.log('hello')} } f = dostuff(); f(); --output:-- hello . Array.prototype.greet = function() {console.log('hello')}; [1, 2, 3].greet(); --output:-- hello . function Dog(name) { this.name = name; this.speak = function() {console.log('Ruff, ruff!') }; } mydog = new Dog("Joey") console.log(mydog.name); mydog.speak(); --output:-- Joey Ruff, ruff! . function Dog() { } Dog.prototype.speak = function() {console.log("Ruff, ruff!")}; mydog = new Dog(); mydog.speak(); --output:-- Ruff, ruff! . function Dog() { } var obj = { name: "Joey", speak: function() {console.log("Ruff, ruff!")} } Dog.prototype = obj; mydog = new Dog(); console.log(mydog.name); mydog.speak(); --output:-- Joey Ruff, ruff! obj.jump = fun

Categories : Javascript

recursive function - help returning value when calling function
function find_percentile($search, $type, $score){ $max = null; $where = 0; foreach($search as $key=>$val){ if ($val[$type]== $score){ return $key; } else if($val[$type]>$max && $val[$type] < $score) { $where = $key; $max = $val[$type]; } } return $where; }

Categories : PHP

jquery function not returning html to second function
Problem solved: function loadTravelRules(id){ $.ajax({type: "GET",url: "CFCs/myapprovers.cfc",dataType: "json",data: {method: "MYAPPROVERS_RLUz",MYAPPROVERSID: id },success: function(response){ var rdata = response.DATA; var str = '<ul">'; for (var i = 0; i < rdata.length; i++) { var aid = response.DATA[i][response.COLUMNS.indexOf('MYAPPROVERSID')]; var auditor = response.DATA[i][response.COLUMNS.indexOf('DEPTAUDITAPPROVEREMPLID')]; var firstApprover = response.DATA[i][response.COLUMNS.indexOf('FIRSTAPPROVEREMPLID')]; var secondApprover = response.DATA[i][response.COLUMNS.indexOf('SECONDAPPROVEREMPLID')]; var thirdApprover = response.DATA[i][response.COLUMN

Categories : Jquery

Sort a php array returning new array
Would you be able to do this? $some_mixed_array = array( 998, 6, 430 ); function custom_sort( $array ) { // Sort it asort($array); // return sorted array return $array; } custom_sort( $some_mixed_array ); // returning: array( 6, 430, 998 ) This would also solve your issue: $some_mixed_array = array( 998, 6, 430 ); echo '<pre>'.print_r($some_mixed_array, true).'</pre>'; asort($some_mixed_array); // <- BAM! // returning: array( 6, 430, 998 ) echo '<pre>'.print_r($some_mixed_array, true).'</pre>';

Categories : PHP

CoffeeScript function returning a function and not a value
So the data you are getting from firebase is event-driven and asynchronous, so you can't just return it as if this was synchronous code. You need to use a either a callback, a promise, or event handler. getCars = (userId, callback) -> id = parseInt(userId) userRef = new Firebase("https://demo-firebase.firebaseIO.com/users/#{id}/") userRef.on 'value', (snapshot) -> if snapshot.val() == null callback ["toyota"] else callback snapshot.val().cars # returns an array of cars userInfo = id: user.id email: user.email getCars user.id, (cars) -> userInfo.cars = cars #Don't user userInfo until here as it's not ready/populated yet! (Note the node convention is callback(errorOrNull, value), but I'm omitting error handling here for simplicity) Also note t

Categories : Javascript

returning outer function from inner function
you could reformat the code so that your if conditions are only modifying the parameters. Then you just call your method with the correct parameters at the end function MyFunction () { var params; if (SomeCondition) params = SomeParam; else if (SomeOtherCondition) params = SomeOtherParam; else if (SomeThirdCondition) params = AnotherParam; MyInnerFunction(params); }

Categories : Javascript

Returning false on a function that contains another function
How should I go about doing this? You can't (well, not reasonably). Ajax calls are asynchronous. By the time the ajax call completes, the call sortable made to change has long-since returned. While you could (for now) make the ajax call synchronous, that's not usually a good idea as it locks up the UI of the browser during the call. jQuery will be removing the async flag in a future version. So the correct thing to do is not rely on the result of the ajax call in change; come at the problem a different way (perhaps saving some state and restoring that state if required).

Categories : Javascript

PHP SQL Array not returning anything
I assume lead_id is a field in DB so you don't need quotes for it: AND lead_id = '$entry_id' You're also going wrong by putting variables directly into the query, you make your app vulnerable to SQL injections. consider using prepared statements.

Categories : PHP

Function Returning Itself
No, you cannot declare recursive function types in C. Except inside a structure (or an union), it's not possible to declare a recursive type in C. Now for the void * solution, void * is only guaranteed to hold pointers to objects and not pointers to functions. Being able to convert function pointers and void * is available only as an extension.

Categories : C

PHP function not returning value
you have no return statement under this condition block. i have added return there. if($passwordLength > 8) { $encryptString = substr($inputPassword, 0, 8); $inputPassword = substr($inputPassword, 8); $newPassword .= crypt($encryptString, "HIDDENSALT"); return crypt_password_input($inputPassword, $newPassword); }

Categories : PHP

COUNT returning array?
if $connect is mysqli object: $total = $connect->query(" SELECT COUNT(*) AS `count` FROM photos WHERE gallery = '$row[id]' ")->fetch_assoc(); // $total['count'] Notice: Use PDO library and param binding to prevent sql injections.

Categories : PHP

php array not returning full out put
You're only reading one block of 4096 characters from your stream. if your folder list is longer than this you'll lose the rest. You need something like this: stream_set_blocking($stream, true); $item = ""; // continue reading while there's more data while ($input = fread($stream,4096)) { $item .= $input; } $items = explode(" ", $item); print_r($items);

Categories : PHP

2D array of Doubles returning 0
Your typecast is in the wrong place. Your expression (double)(1/(i+j-1)) will almost always be 0 due to integer division. You will get 1 out when i == j == 1. You probably want: 1.0/(i+j-1)

Categories : C++

Returning an array from the model
App.Player.find() returns a promise, and therefore you should wait until your records are fully loaded before doing operations on them. From your question it's not entirely clear how you player objects do look like. But to get to your players, and especially to your player's properties, you could do something like: var playerList = App.Player.find().then(function (result) { // This callback will fire when array is loaded // and this is the correct way to get to the records result.objectAt(0).get('name'); // assuming "name" is a property of your model // here you can then loop over your obejcts result.forEach(function(item) { console.log(item.get('name')); }); }); Hope it helps.

Categories : Ember Js

Returning an integer array
Try: int foo(int arrayBar[]) or int foo(int* arrayBar) or int* foo(int arrayBar[]) If those don't work, make sure your pointer is at the beginning of the array. Source: c++ return array in a function

Categories : C++

Returning an Array from a file
You should just store the array as ... an array, like so: file_put_contents('myfile.txt', '<?php return ' . var_export($array, true) . '; ?>'); Then, to read: $array = include 'myfile.txt'; See also: var_export()

Categories : PHP

Returning an Array using Firebase
The problem occurs in getPosts(). It pushes a promise into your array inside an async function--that won't work since q.all is called before the promise objects have been added. Also, child_added is a real-time event notification. You can't use that as a way to grab "all of the data" because there is no such thing as "all"; the data is constantly changing in real-time environments. FirebaseIndex is also using child_added callbacks internally, so that's not going to work with this use case either. You can grab all of the posts using the 'value' callback (but not a specific subset of records) as follows: function getPosts() { var def = q.defer(); Firebase.child('users').once('value', function(snap) { var records = []; snap.forEach(function(ss) { records.push( ss

Categories : Node Js

webservice not returning a array
Assuming your data is like the following: $return = '<?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org /2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GETOfertasAereasResponse xmlns="http://tempuri.org/"> <GETOfertasAereasResult>Some result content</GETOfertasAereasResult> </GETOfertasAereasResponse> </soap12:Body> </soap12:Envelope>'; Try this: $obj = new SimpleXMLElement($return); $body = $obj->children('soap12', true)->Body->children(); $content = (string) $body->GETOfertasAereasResponse->GETOfertasAereasResult; var_dump($content);

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.