C++ :: How To Tell Function Which Part Of Struct To Use
Jul 4, 2013
Say I have a structure defined as such:
struct data{
char c;
int x;
};
And I want to create a function to print either c or x. However, I don't want to just use a switch or something to figure this out, I want to reference which part I'm outputting.
Now here's the twist
vector<data> dataList;
I need to access element x or c in the vector, but all I pass is the vector and which element, so that I might have something like:
How can I Passe some part of multi-Dimensional Array to a Function; for example only two dimension of three dimension of a an array with 3 dimension. This is because my function is defined for working with 2 dimension arrays.
I understand template functions and how to call them explicitly when no arguments are passed to them but can't seem to instantiate them explicitly when it resides within a class or struct.
You should be able to enter those fields, and after some time when while loop is stopped (when u press n) it should print out that PhoneBook bellow. I don't understand what is the problem but I think it is that Display function.
Code: //prototype void improvedbubblesort (struct team Table[]); //this is defined out side of main
[Code]....
the whole code is very long but can post if necessary . Basically i get no errors in this but its not sorting them . Think its in the way i pass the array of struct .
I have some code here where I try to declare a struct then pass it as a parameter into a function to do something to it:
Code: struct _user { char * initial[3]; int pos; } user; int initial_add (struct user * initial_list, int initials, char * buffer) {
[Code] ...
I get the error : server2.c:15: warning: "struct user" declared inside parameter list server2.c:15: warning: its scope is only this definition or declaration, which is probably not what you want
In this program I am attempting to allow a user to input three different authors and then input three books they have written as well as the price. I am struggling with calling the functions and am not sure what to do.
I am working on incorporating a function in to an already existing piece of code, I have incorporated the function fine as far as I am aware.
The problem I have is that I am trying to pass two int arrays to the function, so that i can manipulate and compare them "the values will be changed the originals cannot be changed"
I am having trouble pulling the information out of the already created array, I am able to pass the pointer reference for the single value which is not exactly what i want "best_prog".
My function is below I have commented the memcpy parts and also the majority of the code isn't there cause it is not needed to see make the copy work.
int edit_distance(int index) { struct prog *progp = &population[best_prog]; /* The struct of best prog not sure if i need one for the other prog I am trying to compare it with the one below doesn't work as intended.*/ //struct prog *progp = &population[]; int editdistance = 0, ar1 = 0, ar2 = 0, a = 0, b = 0, j = 0, x = 0;
I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.
My problem is accessing the array to search through.
Here is my code:
Code: #include "stdio.h" const int IDLEN=30; //All constant values defined const int POLARITYLEN=3; const int MAXSTOCKITEMS=10; //First structure defined struct TransistorRec {
[Code]......
The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'
i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct { int x; } void my_function( my_struct** result ) { my_struct* x = new my_struct{ 10 }; //... *result = x; }
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
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.
int count = t1; while(count>counter){ Sleep(delay); Int32::TryParse(textBox2->Text,add); result = result + add; counter = counter + 1;
Problem is that sleep stops all program for specified time, Is there an alternative to sleep that would only stop part of code or can i use sleep different way to specify what it pauses?
Is there any way I can clear only a selected part of the screen? (I'm aware of system("cls"))
For example, when you enter a date, and is wrong, could it just errase that input and only say "Wrong try again" without errasing everything else you where doing?
In this case, a function that only errases what is in the while
I am having a little bit of trouble with what should be a simple part in my code. For some reason it keeps looping the name part of the program and I seem to be passing over the problem in the code.
Here is the code:
#include <iostream> #include <string> using namespace std;
Code: // string::erase #include <iostream> #include <string> int main () { std::string str ("This is an example sentence."); std::cout << str << ' '; str.erase (10,8); std::cout << str << ' ';
Code:
Output:
I don't understand this program. What do these 2 numbers represent? The index of an element in a character array? The 10th character of the array is 'n' and 8th is a "space".
I'm having a problem converting part of a string to an integer.I used strtok to seperate my string and I have also a function for atoi but how to apply it to my strtok function.What i need is to change the char *years to an int.Have a look of what I got:
Code: int main() { char sentence[]="trade_#_2009_#_invest_#_DEALING"; char *word=strtok(sentence, "_#_"); char *year=strtok(NULL, "_#_");; // assigning NULL for previousely where it left off char *definition=strtok(NULL,"_#_"); char *synonyms=strtok(NULL,"_#_");
I have a character array that includes configuration bits that are 0x00, thus when I try and do a strcat it adds the appended string into one of those spots instead of the end of the array.