C/C++ :: How To Pass Structure Variables Between Functions
Jul 13, 2014
I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.
My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:
This works if the function pointer being passed to the event manager is not a member function.
I have two other classes Scene and Object that could potentially use this EventManager to create callback events. Scene and Object are both pure virtual objects. How can I pass a pointer to a member function of the child classes of both Scene and Object? I am fine with just having two separate watchEvent functions for Scene and Object but how do I pass the type of the Object or the type of the Scene? The child classes are unknown as they are being created by someone using this game engine.
For example, if I want to make a player object it would be something like
class PlayerObject : public Object{...};
Now that PlayerObject type has to find its way to PlayerObject::functionToCall(). I think I need templates to do this but, since I never used them before
This is how I intend to use this
class OtherScene : public Scene{ void p_pressed(void){ //pause }
How to pass arguments from other functions to main. i want to write a program like nano well not exactly like nano editor. I have a function f_read(char* filename[]), and fopen() get filename[1] as file name and *filename[2] as "r" read mode and rest of the code will read from a file.
I want is this char filename[] to main(int argc , char argv[])
I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:
//The class need to have constructor. Class ABC { public: DWORD *IdG; ABC(int number) { IdG = new DWORD[number]; } }obj(32);
The obj(32) is called in following two function. Function F1 is called using thread in main function.
void F1() { obj.test; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { obj.test1; _beginthread(F1,0,(void*)number); }
The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.
If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.
How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.
I have an array of structure that takes family information (name, age, and state) after it takes the users input it prints back all of the information that was input and then prints the family members that just live in Texas. After that I am trying to implement a function to average out the ages of all family members but I cant seem to get it right, whenever it gets to that part of the program it just outputs 0. I also tried adding an & sign prior to FAMILY[i].age and got an error of int from ptr with no cast.
Also I realize that the code only shows adding of the family members ages which is fine for now as I am concentrated on getting that to work in the first place.
I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case. If I don't initialize 'dummy' does it make any errors ? Do I need to initialize hours, minutes, seconds as well before I use the structure ? If so is there any particular reason ?
This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.
I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.
Code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define HIGH 49 #define LOW 1 int random_generated()
I am returning area from areaCircle(), but do not know how to print it in main. I know this program has lots of errors, two cases that I have listed.
Not sure how to properly list multiple function calls in a switch statement, and how to print one's return from main.
int main() { char choice; double area; showMenu(choice); switch (choice) // If input is C, use getRadius, areaCircle and count, then print the are { case 'C': void getRadius(),double areaCircle(), void count(bool display = false);
Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.
I have this code where I am trying to retrieve the contents of the variable dev1 and dev2. for some reason when i compile and run I am getting 0 and 0.
I'm truing to write a function that gets an array of arrays, and returns an array. I placed the code I'm using below, but I'm getting all kinds of errors. How is the right way to do this?
Now the book says to take the following program and add a member function to the CarType class which prints the values of all of its data members. Add two more data members which are relevant for cars. Add the use of these data members to the program (to the assignment statements for MyCar, to the operator prompt and input inside the getYourCar function, and to the print function you have created).
Here is my code. Whenever I run it, it takes my assigned variables in MyCar and prints those instead of the one which the user is inputting.
#include <iostream> #include <iomanip> #include <string> using namespace std; using namespace std; struct CarType { string maker;
Description: Use functions and structures to simulate storage in a warehouse
*/ #include <cstdlib> #include<iostream> #include<cmath> #include<iomanip> #include<string> using namespace std; struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"
[code].....
I keep getting a linker error on every function. what am I doing wrong?
What this is, is a more recent assignment and my question is if my errors are directly related to passing structure addresses to functions. I've tried several syntax variations at the beginning of my loops such as this one:
while (choice != "Q" || "q")
But the loops will not run since I introduce polar to rectangular and the choice element. My last working code was rectangular to polar and all of it worked fine.
#include<iostream> #include<cmath> using namespace std; //structure declarations struct polar { double distance; //distance from origin double angle; //direction from origin
It is said that variables in a function cannot be changed by another function. Only by using pointers can variable values be changed. I am writing some functions to try to prove this theory, but I can't get it right.
Code:
#include <stdio.h> #include <stdlib.h> int main(void){ int x = 10; printf("default x value is %d ",x);
[Code] ......
Code:
#include <stdio.h> void try1(int x){ printf("x in try1 is %d ", x); x++; printf("x in try1 after ++ is %d
I need making my main function to run while not having any if or for statements. It can only declare variables and functions. Since my main function has command line arguments, how to so.
// This program counts all the words in a given file.
There are, or course, better ways to do this, but I need to stick to some rules:
(1) Use only pointer variables and not arrays or structs. (2) Use the three functions shown--regardless of easier methods.
The program should ask for some input, operate on those numbers, and then display the results. I know I am confused over these things:
(1) All that syntax using '*' and '&' or neither. (2) How to use the char type correctly. (3) How to use a char type input as an operator (a + b). (4) How to use the pointer of the operator variable (+,-,*,/) in an actual equation.
So I need to make a main function have no if/for/etc. statements so I need to move it to another function and call it in main. The problem is that it's a command line argument function so I'm confused on how it works. Here's an example:
Code:
#include <stdio.h> int main(int argc, char* argv[]) { printf("The program name %s", argv[0]); if (argc == 2) { printf("Argument supplied is %s", argv[1]); } else if (argc > 2) { printf("Too many arguments");} else { printf("One argument");} }
How can i make this into two functions with main only declaring variables and calling other functions?