C :: Function That Returns ARRAY And Its SIZE?
Dec 24, 2013
to return the array i shall make a pointer function thats ok.. but how do I get the size return if i dont know the size?
if I need to make AXB=C and output C my new array doesnt have a size..
View 7 Replies
ADVERTISEMENT
Jan 21, 2013
Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.
View 6 Replies
View Related
Mar 20, 2013
I have an assignment which requires me to do the following:
Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:
- The first parameter is the array to be searched
- The second parameter is the integer to be found within the array
- The third parameter is the size of the array
- The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.
Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)
Code:
#include <stdio.h>
#define SIZE 10
size_t findNumber(int *sort, const int array[],int key,size_t size);
int main(void){
int a[SIZE];
size_t x;
[code].....
View 1 Replies
View Related
Sep 14, 2014
#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;
[Code] .....
I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.
View 9 Replies
View Related
Jun 27, 2014
I'm wondering if it is possible to pass a 2d array to a function where the size of the array is not known at runtime.
I've tried
function ( array[][6] ) ;
But the size of the array has to be constant so it cannot be declared later.
I've tried using a template but you still have to declare the size of the array at runtime. Is this even possible at all?
The only other way I can think of is using a dynamic 2d array but how to create one and manipulate it.
View 2 Replies
View Related
Feb 22, 2013
I made a function like follows:
void foo(const double va, const int q) {
int qaa[q];
......
return;
}
However, the compiler indicates allocator cannot allocate an array of constant size 0... how can I use the argument "q" to fix the size of array "qaa"?
View 8 Replies
View Related
Nov 27, 2013
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
View 3 Replies
View Related
Feb 12, 2014
Write a function that accepts an array of integers and its size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth.
The function should return a pointer to the new array. Use ONLY pointer parameters instead of arrays in both functions; use pointers (not subscripts) to move through elements of both arrays. Before calling the function, display your original array. When the function call is completed, display the new array.
Here is what i got so far:
#include <iostream>
using namespace std;
int *shifted (int * , int);
const int SIZE = 10;
int main () {
int array_size [30];
[Code] ....
View 1 Replies
View Related
Nov 24, 2014
I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:
#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);
[Code] ...
View 3 Replies
View Related
Jun 5, 2014
I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).
The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.
What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?
View 2 Replies
View Related
Sep 4, 2013
I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
Code:
//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;
[Code].....
View 11 Replies
View Related
Jun 24, 2013
For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:
bool setzen(int x, int y){
if(feld[x][y]!=3){
return mine=false;
}
[Code]....
Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.
View 6 Replies
View Related
Oct 7, 2014
How can I show elements of a vector that is returned by a function in main() ?
Code:
vector<int> merge_sorted(vector<int> a, vector<int> b){
vector<int>temp;
int count = 0;
if(a.size() < b.size()) count = a.size();
else count = b.size();
[Code] .....
View 12 Replies
View Related
Mar 8, 2013
Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.
View 3 Replies
View Related
May 15, 2013
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){
... // some local value definition
for(int i = 0; i < 1000; i++){
... // a lot of calculations done here
return i; // -> return the value after each loop is done
}
}
Here it only returns one value, i = 0. Clearly it's wrong.
View 10 Replies
View Related
Oct 24, 2013
I'm writing a function that is to return the price of something.. What would be the most appropriate return type for this? Like in Java it would be a double...
View 6 Replies
View Related
May 5, 2014
How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".
To do this would I just use an array?
View 4 Replies
View Related
Oct 23, 2014
I need to create a function that takes as an input a variable number of scalars and returns the biggest one. Just like std::max() does for 2 elements, but I need it for an undefined number of elements, can be 2, or 5, or 10 etc.. How to approach this?
What I need it for: I'm working with a bunch of vectors, maps, etc. and I need to find out which has the most elements. So I was thinking that I should end up with something like
int biggest = max(vector1.size(), vector2.size(), map1.size(), ...);
View 8 Replies
View Related
Mar 11, 2014
I have a big problem with a function, I wrote this function in order to get a line from an HTML (Or XML) file, until a specified delimiter (not always or
... It can be everything..)
Here is my code :
public static String GetLineUntilChar( String url , char delimiter , String postData, String referer, String cookie ) {
try {
Uri uri = new Uri("http://127.0.0.1//site.html");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "application/x-www-form-urlencoded";
if (!String.IsNullOrEmpty(referer))
request.Referer = referer;
[Code] .....
View 14 Replies
View Related
Mar 17, 2013
I have a matrix that contains zero and nonzero elements. I want to do a function that return 3 arrays.
The first one is for nonzero elements the second array contains the corresponding row numbers of each nonzero element the third array contains the corresponding column numbers of each nonzero element.
View 11 Replies
View Related
Mar 21, 2014
Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1.
HAVE TO USE FOLLOWING FORMAT:
Code:
// POST: Returns the number of reversals needed to make arr[0] == 1
// if the reversal game were played on arr
// Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster;
[code]....
View 2 Replies
View Related
Feb 18, 2015
Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {
[Code] ....
View 2 Replies
View Related
Mar 1, 2013
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
View 8 Replies
View Related
Aug 25, 2014
Here's the code that returns maximum sum of a subsequence from a given array. This is according to "Programming Pearls" by Jon Bentley. I have come up with an example for which this program won't work. And here's that example:
{ -10, 11, 10, -10, 2, 3, -6, 1 }
Max subsequence sum above is 21. 2nd and 3rd elements.
But the program returns 16. It sums 2nd through 6th elements and returns. Why would the writer explain something with such depth, only to give a program that doesn't work in all instances?
int MaxSum(int lo, int hi, int* arr) {
if (lo > hi) {
return 0;
}
if (lo == hi)
[Code]...
View 11 Replies
View Related
Oct 21, 2014
The question is to write a recursive boolean function that compares two stacks and returns true if they are identical. This is where I get stuck:
If the top items of both stacks are the same, the recursive call always returns true, because 'true' is saved on top of the return stack.
Here is my code:
template<class Type>
bool identicals(stackType<Type> s1, stackType<Type> s2) {
if(!s1.isEmptyStack() && !s2.isEmptyStack()) {
if(s1.top() != s2.top())
[Code] ....
View 2 Replies
View Related
Dec 23, 2014
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
View 4 Replies
View Related