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. */
#include <iostream> #include <cstdlib> using namespace std;
[Code]....
I am trying to initialize int x[] = {10, 100, 1000, 10000} into a loop and give me four different numbers for something. I was trying to get creative and just do
I have an array as such and need to multiply all the values of it by each other and put that as a variable.
//for example int array1[100] //assume i have already input the values of each element properly up to, say, element 4 //I need to now multiply all of those values together. I think I need the size of the array to control what it multiplies (I know how to find size) ....
I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:
How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.
example:
Code:
void X(int *a, int*b){ a= malloc ... b = malloc ... // fill a and b return them back to the main function } void main(){
I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.
I'm trying to create an array of function pointers and then assign compartilbe functions to them, so I can just call *pf[0](xxx);
The functions are all of the type
void func01(unsigned char*, int, int)
how would I create an array of function pointers and assign the address of the functions to them? So I could call them like
ptrToFunction[i](charBuffer, 10, 20);
I've read a bit on line and I thought I could do it but so far I've failed.
It seems trivial and I feel I'm close but close isn't good enough.
I'd like to assign the fuction addresses like this: for (int i=0; i<10; i++) if (i==1) ptrToFunction[i]=func01; if (i==2) ptrToFunction[i]=func02; etc.
The actual logic is somewhat different than this but this close.
The premise of this assignment is to create a menu driven, array of functions calculator. This is the code I have thus far (I haven't finished all of my comments yet, I've been to focused on clearing errors).
/*prototypes*/ void sum (int a, int b); void dif (int a, int b); void pro (int a, int b); void quo (int a, int b); void printMenu();
[Code] .....
I am using Visual Studio as a compiler, and I have the following errors:
error C2144: syntax error : 'int' should be preceded by ')' error C2660: 'sum' : function does not take 0 arguments error C2059: syntax error : ')' error C2144: syntax error : 'int' should be preceded by ')'
[Code] .....
I can only assume that I am making simple mistakes.
I am on a project. I have a laptop and It doesn't have a COM port. So what I would like to do is to get a usb to RS232 cable and write a code so to output voltages on usb and measure it on the RS-232 end. Can I vary the output voltage to my needs?
I have a Voltage Range from -10V up to +10V, which I transform to a voltage Range 0V to 5V, with the schematic i've attached, so I can use the A/D converter of my ATMEGA32 processor.
Now I'd like to write the value of the Input Voltage (which moves in the Range of -10V to + 10V) on the serial port, but i don't know how i should calculate this factor. At the moment, I can only write the value of the A/D Converter Input on the serial, but this is only 0V to 5V...
My code seems to find the mode of the array I input sometimes. Sometimes it gives me the wrong number or multiple numbers. It just all depends on what is number is inputted into the array. I don't know what the problem is. I tried looking online and editing many times and can't find the answer. Maybe I'm overlooking something or doing something wrong. Here's my code.
int main() { int x = 1; char *y = (char *) &x; printf("%d ", *y); }
The output will be either "0" or "1" depending on the architecture of the system.When I executed on my system I got output as "1", now what is the architecture of my system is it 32 bit or 64 bit?
I am so close to finishing this program. It will find the median of an array of 5 values. I have one last error that I cannot seem to get to go away. Here's the code:
#include <algorithm> #include <functional> #include <array> #include <iostream> using namespace std; int main() { int integer1, integer2, integer3, integer4, integer5;
[Code] .....
The error states: "IntelliSense: no instance of overloaded function "std::nth_element" matches the argument list, argument types are: (std::_Array_iterator, std::_Array_iterator, unsigned int, std::_Array_iterator)
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 very new to C++ so I've been trying to run through some code examples to begin to learn basic structures and syntax, but I've recently run into a problem using examples from the 7th ed. of Sams Teach Yourself C++. I'm using the code provided within one of the examples that allows you to specify and multiply two variables, but when I compile and run the executable the final output seems to only show the first variable and b/c of this the multiplication operation does not work.
Here is a my example code:
Code: #include <iostream> using namespace std; int main() { cout << "This program will multiply two numbers" << endl;
we have to make a Invoice class which has a function called computeInvoiceAmount() which multiplies the price and the quantitiy which are private member of the class.
Two different matrices will be read from text files (input1.txt, input2.txt) and they will be stored in two dimensional arrays (matrix1, matrix2) and one dimensional arrays (array1, array2). Our aim is to obtain the matrix multiplication using two dimensional and one dimensional arrays.
You are asked to write the main and the following functions. The definitions of the functions are given in the skeleton code.
int read_file(ifstream& in_file, int &row, int &col, double *array, double **matrix) int write_file(ofstream& out_file, int row, int col, double **matrix) void print_matrix(double **matrix, int row, int col) void print_array(double *array, int row, int col) void multip(double **matrix1, double **matrix2, double **result, int k, int m, int n) void multip_array(double *array1, double *array2, double *array_result, int k, int m, int n)
You are going to obtain the input and output files as command line arguments
input1.txt : 3 4 2 3 4 5 1 3 5 4 0 4 4 7
The first element in the first line represents the number of rows (3) and the second element represents the number of columns (4) of the matrix (the result file will have the same format).
thats my homework and here is the code i wrote from the sceleton code they gave me :
#include <iostream> #include <fstream> #include <string> using namespace std; int read_file(ifstream& in_file, int &row, int &col,/* double *array,*/ double **matrix)
[Code] ....
I didn't understand the array part but even when i exclude the array part i get the program has stopped working message. My os is windows7 ultimate with mingw installed and i compile the program using g++ command in cmd with the arguments input.txt input2.txt resultt.txt