I'm having issues with pointers and relationship operators in C.
I need to find a max and min value in a void function using pointers. max and min would work if they had values. mul works, because you can just do math operations with pointers.
There are 0 errors and warnings; but max and min are never going to work as is.
Clearly I'm missing something.
#include <stdio.h> #include <stdlib.h> void max(int *a, int *b, int *c, int *d, int *result); void min(int *a, int *b, int *c, int *d, int *result); void mul(int *a, int *b, int *c, int *d, int *result); int main()
[Code]...
Your job will be to create a program that uses pointers. Your output must be done in the main function and the calculations MUST be done in the three functions. Therefore you MUST use pointers correctly.
You must declare and implement the following 3 functions. Below are the three prototypes that you must use in this program.
void max(int *a, int *b, int *c, int *d, int *result); void min(int *a, int *b, int *c, int *d, int *result); void mul(int *a, int *b, int *c, int *d, int *result);
The functions have the following meaning:
max finds the max value of a,b,c,d and stores the largest value in result. min finds the min value of a,b,c,d and stores the largest value in result. mul multiplies a * b * c and divides by d. Stores that value in result.
Below is an example input/output. This input will be read in via the keyboard (use scanf).
input output (note that user input is shown in bold) 1 2 3 4 Enter the 4 numbers: 1 2 3 4 The max is 4. The min is 1. (a * b * c) / d = 1 100 3 201 103 Enter the 4 numbers: 100 3 201 103 The max is 201. The min is 3. (a * b * c) / d = 585
Your output MUST match exactly the output below for the input from above. Your program must compile, failure to do so will result in 0 points. */
That this will execute those binary instructions in hexadecimal notation BUT WHY? I don't get why that works since that's an array of data not a function?
I am trying to add data to a queue with the following simplified code:
Code: typedef struct Queue { void * data; int head; int tail; int elementSize;
My question is, how do I move the queue->data pointer to the correct memory location in order to copy given data to head? The code above inside memcpy gives med the error: "expression must be a pointer to a complete object type".
Do I need an extra pointer to be able to navigate between the queue's head and tail, and keep queue->data as a reference to the first byte of the allocated memory, or is it possible with only queue->data?
Edit. Just noticed I have mixed up head and tail. The enqueued data should probably go to the Queue's tail and not the head. However, the problem is still the same.
I want to know how to dereference a void pointer through the way of typing it.
Lets just say that I malloc'd a huge bunch of memory and i can do whatever i want
void* randomData = malloc ( 1000000 );
And i decide to make my own virtual 'int'
I am not sure how to do this.
*( int* ) ( randomData + 10 ) = ( int ) 323453 //323453 can be an int variable aswell
Im not sure if this is the right way to do perform a dereference.
This is an overview of what has to be done: -The pointer has to be dereferenced -Cast the pointer as an int pointer so we can change it like a normal 4-byte int -Perform pointer arithmetic, so that the int can be placed anywhere we want
I am trying to find the distance between two void pointers, so I can follow this distance to a certain pointer in a vector when given only the previous element in that vector.
int distance = (char*) prev - (char*) first; next = (char*) cv->elems + cv->elemsz + distance;
Basically, prev and first are void pointers. I am trying to cast them into a char, subtract the first element in the vector from the previous one, and then use this distance to determine what the next element in the vector is. However, it is not working. I am not sure how to do this. To complicate matters, prev is a const void *.
I'm trying to pass 2 arrays into a void funtion, and return values to one function.
this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.
#include <iostream> using namespace std; void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize); int main() { int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189}; int numberCount[8] = { 0 };
[code]...
The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.
I have a void that needs to end a program but a break and return 0 both won't work. Instead I have it cout (1/0). It works but is there an alternative?
I was reading about void as function argument, but I did not fully understand it's meaning in C.
In C++ void foo(void) {} and void foo() {}
are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means
In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?
For example.
void foo() { printf("%d", var); } foo(5);
It is very unclear for me. Do this apply to main function too?
int main(void) int main()
or can I use arguments given to int main() like given to int main(int argc, char* argv[])
I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.
#include<iostream> #include<fstream> using namespace std; void bubbleSort(); void selectionSort();
How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.
In my Class:
void Utility::someFunction(int var1, int var2, void customFunction) { int num1 = var1; int num2 = var2;
Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?
Code: #include <stdio.h> int compareid(void* info, int value); // ansi declaration int compareid(void* info, int value)
I am new to C++ ... My question is if I were to pass some data or values from the main() function through a void function (which main purpose is to display the data in a certain manner); how should one go about doing so?
For instance:
Code: // example.cpp -- poorly written, just trying to learn #include <iostream> void format() { using namespace std; cout << "Time: " << min << hrs << endl;
[Code] .....
Obviously this is really poorly written, and confusing for the user. My main goal is to learn how to pass through values to a void function.
Also a bit off-topic, but is there a downside to place "using namespace std;" outside a function say if out of 100 functions only 10 of them use it? Would it make the program slower/unstable in any way or is this something one could do without any downsides?
I have the following void function devised to assign "+1" or "-1" to each element of a matrix at random. While the function does what I want, when I print the values of the matrix all are set to zero:
#include <vector> #include "aRand.h" #include <iostream> void initConfig(std::vector<std::vector<int> > premat, int nL, int nN) { int * pnRand; pnRand = 0;
[Code]...
The function pnRand_plus returns a pointer to an array of random numbers from 1 to 100, with seed time(NULL) + i. The values printed in main are zero, despite the values printed during the function run are fine (-1s and +1s).
I made a basic console calculator in C++ using the Code::Blocks IDE and using the GNU GCC compiler. The problem in my code is my void function called 'operate' is getting ignored by not showing up in the console. After the first if statement I added a user input by saying Y for yes or N for no. Another if statement inside the first one shows if you type either 'Y' or 'y' it will execute the 'operate' function which will restart the calculator by having the same selection menu as in the int main function. When I call the function it does not show up in the console but just ends the program.
Here is my code:
#include <iostream> #include <cstdlib> #include <string> using namespace std; int input,input2, numAdd, numAdd2, numSub, numSub2, numMult, numMult2, numDiv, numDiv2; void operate() { cout << "Select a operator." << endl;
So I am writing this code that analyzes a file called "analysis.txt" and prints out in an ouput file (called "report.txt") the results of the analysis, i.e.,(the frequency of all alphabet letters present in the file).
I am having trouble with outputing on the file2.
here is what I have:
Code:
#include<iostream> #include<fstream> using namespace std; ifstream file1;
[Code]....
I tried to lose the "<<" after the file 2, but it's still giving me an error. how to output a void function on a text file?