So I have to type couple of numbers, and find first bigger odd and and first smaller even, and print them in function. So I guess, its void function. Now, I gotta question, how to do it? This is my code, don't mind printf-s, its croatian languge, I just want to know how to transfer array to function. I see alot of people doing it with pointers, but we still havent got to them, so I wonder is it even possible to do it without pointers?
Code:
//!!!CODE DOES NOT WORK!!!
//IT COMPILES, BUT AFTER INPUT, ERROR OCCURES
#include <stdio.h>#define UK_BR 2
void parniNeparni(int brojf[UK_BR]);
int main (){
int broj[UK_BR],i=0;
for(i=0;i<UK_BR;i++){
[Code]....
We're on vacations now, and the professor didn't show us how to do it, and its my homework that has to be done until we get back to college.
The next step for my project is to take data from a file, and create a new file with the same data, but in reverse order. If a file has the following values:
1 2 3 4 5
The program should create a new file with the following values:
5 4 3 2 1
Seems pretty straight forward, yet I am hitting a snag when I try to compile my program:
The following errors occur when I try to compile the fore mentioned code:
intrev.c: In function 'main': intrev.c:25: warning: unused variable 'out' intrev.c: At top level: intrev.c:39: error: expected identifier or '(' before 'while'
[Code] .....
Now I am not concerned with "unused variable 'out'" as it is used, just in a for loop. Is this a problem?
I'm not entirely sure why it's giving me the error at line 39. I've gone over this a couple times and it doesn't look like I've missed any methods which need to be closed. Maybe I've missed something?
I'm also not sure why I am getting an error when I try to close the opened files. I've done this before in the same manner, but without errors. Not sure why I am now, but my guess is that it has something to do with the error on line 39.
I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function
#include <iostream> #define random(x)(rand()%x) // for random number between numbers of 0 and 1 using namespace std; void proc1 (int iArray[][2]); void proc2 (int iArray[][2]); void selectfunction(int iArray[][2]); int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };
im trying to read in 1 array and get 2 as outputs from 3 different functions.my read array is easy enough were im getting confused is how to read that array, separate it and take out only the parts i want and place them into a 2nd, then again a 3rd array.i have the following so far:
this compiles without a complaint, but when i go to run it no longer responds after taking the 10th element (well 9th if counting from 0).I think i have the if correct for the even odd section, but when i try to populate B or C array with the output of that if statement from A is were i think things are dying...
I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.
Code: #include<stdio.h> void display(int array[],int size) { int i;
[Code]....
With this code I want to print the five elements from the element present in [0][4].
But shows an error that
Code: D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':| D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]| D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'| ||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?
use 2D array in function and change the array values. I do not know if I can use array by calling from a function. I have 6 row 6 column array, I used it inside a function and for the another function I just need to change 4. row 4. column and I do not want to type array to just change one part. I do not know if there is another way or not
I need to use 3 different functions. The first function should read in N amount of integer values from the user.If any values are less than 1, store a value of 0 instead of the input value.
Second should go through the entire array to find the largest value and send the largest value back to the main program. The last is just an output function where I write out all of the array values and the largest value.
Here is the program.
using namespace std; #define ARRSIZE 20 void getData(int A[]); void findBig(int A[ARRSIZE], int max)
I want to write a function that can accept any arbitrary array of doubles and return the index of the first element that is out of order or -1 if the elements are in order. Why my for loop exists immediately after an element is found to be out of order. What is wrong with my code and why?
Code: int out_of_order(double stuff[], int size) { int i; //run through entire array
Code: Int** d = malloc( ROWS * sizeof(int*)); for (i = 0; i < ROWS; i++) d[i] = malloc(COLS * sizeof(int)); fx(d);
My question is, in a function declaration, why do I not have to specify the number of columns. How is this different than when I pass a static 2D array to a function, in which I must declare the function parameter with the number of columns.
Code: void fx(int d[][COLS]); VS. Code: void fx(int **d);
ive been struggling a bit with passing arrays between functions but have most things working. the sum function works fine but the averaging one crashes when it tries to leave the function and return to main. so it prints the first 2 values of output at the end there and then dies. i have all the proper declarations and libraries.
also, how can i properly find the size of an integer array? like ive used sizeof but i dont know how long the output will be so can't calculate the required size to delcare it :
Code: int main() { int start_array[25] = {1,2,4,8,15,9,7,4,2,2,1,3,4,8,13,20,15,8,5,3,2,1,1,0,'$'}; int avg1[256];
I want to pass array to function, to fill array with new values and then to print the array in the main. But I have problem because it prints me just array of zeros. Maybe the concept is wrong, I'm new with passing arrays to function.
function:
Code: void printSum(int *return_array) { int return_array[3]; int i; for(i = 0; i < 3 ; i++){ return_array[i] = 5;
Code:
void printSum(int *return_array); int main { int m_return_array[3]; int i,j; for(i= 0 ; i < 3 ; i++){ m_return_array[i] = 0; } printfSum(start,m_return_array);
I need to pass a 2D array to a function. I want to know, where I may have made a mistake. This is the piece of code that I found on the web, and I am using it to allocate my 2D array.
Code: signed char allocate2D( int** arr2D, int rows, int cols ) { int i; arr2D = malloc( rows*sizeof( int* ) ); if( !arr2D ) return -1;
[Code]....
My main function passes the 2D array to the function
Code: signed char read_root_message_file( int **Root_Messages, int *num ) This is how I pass the array in the main function to the above function:
Code: int main( int argc, char *argv[] ) { int **Root_Messages; ... ... Root_Messages = NULL; read_root_message_file( Root_Messages, &num_root_msg );
I'm trying to define a 7x5 array in main and then use it in a different function that will fill that array with random floats between 0.0 and 1.0 and then use main to print the final, filled array.
I am following a tutorial and the topic was passing array to function so i tried to do a BMI calculator by myself. I am using code blocks to compile the codes, it is actually working while using compiler's run button. But when I open the exe file, its closing the window after entering the persons' weights and heights. Here is the code
Code:
// Passing array to function example BMI calculator of n person #include<stdio.h> #include<math.h> void assess(float bmi[],int a); int main(void){ int n,i,j; }
typedef struct ArrayList { char **array; //number of elements inside list int elements;
//length of array int maximum; }
ArrayList; I've already created a pointer to ArrayList called "mylist" but this list only has a size of int maximum =10....I want to be able to call expand ArrayList in one of my functions incase I need to make my list greater than the size I already allocated for it. expandArrayList(myList, myList->maximum*2+1); is what I would call inside of my function if I needed to expand the list and here is my actual function...
Code:
ArrayList *expandArrayList(ArrayList *myList, int length) { int i; char **newArray; myList->array=malloc(sizeof(char*)*length);
[code]...
I need this code to allocate a new array of length, which would now be 21. Then I need to copy the contents of the lists old array into the new array...Which I am very confused on this part... I created a temporary char **newArray but I don't know if its even taking any of the strings in. I then need to point the old list->array to the newly created array, update all of the values for elements and maximum and then return a pointer to ArrayList... I've tried a bunch of different code and nothing seems to be expanding my original list at all.
I need to create a function which will print a list from 100Hz to 1000Hz then 1000Hz to 9000Hz. I have created a function in order to calculate and set up the frequency values from 100Hz to 9000Hz using two for loops as shown below. However I am unsure how to return this to the array at the main.
int main(void) { double Frequency[18]; system ("PAUSE"); return(0); } double Frequency (void) { int count;
I'm trying to pass an array from one function to another without resorting to pointers and I have to use Pass by Reference. I can't seem to figure it out. I've been looking at many examples and just don't get it.
the function createAbc makes an array populated with the Alphabet. I need to pass that into my display function so that i can work with the array there. I don't know how to pass it in there... :(