C :: Making Function That Will Return Pointer To Long Variable?
Feb 7, 2014
I am making a function that will return a pointer to a long long variable. For example, I have the next variable prototype: Code: long long funcName(long long x, int s); I want to change the return value, and the first parameter to pointers to long long.
View 4 Replies
ADVERTISEMENT
Apr 1, 2015
I have a long long int k=0x0000888804eaad0e
And i need the reverse of this (nibble wise) in other long long int variable.
That is i want the result to be = q=0x0000e0daae408888;
Or the result also can be like this = q=0xe0daae4088880000;
How to accomplish the above?
View 4 Replies
View Related
May 1, 2013
I am trying to return a pointer from a method. Below is a sample of my code.
CSubnode * CTest::GetSubNode() {
return m_psubnode;//this is declared in CTest as CSunbnode * m_psubnode
}
//in another class
m_subnode = m_ptest->GetSubNode(); //m_subnode is declared as a pointer
Is this the correct why to return a pointer?
View 2 Replies
View Related
Dec 25, 2014
I want to get a random number from this function but idk if I did this function right....
int random(int x) {
srand(static_cast<unsigned int>(time(0)));
int randomN = rand();
x = (randomN % 10) + 1;
return x;
}
View 5 Replies
View Related
Mar 17, 2013
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...
View 3 Replies
View Related
Aug 15, 2013
I want to write encryption algorithm.first af all I need to define variable( binary input ) that it is 256 bit but I dont know what should I use...then I want to XOR this to variable ( a & b ) ( each of them is 256 bit)
View 6 Replies
View Related
Apr 3, 2014
How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!
View 16 Replies
View Related
Aug 3, 2014
So I have been given and as part of the solution I need to count the number of digits in a long long variable. To do this I use a while loop, but it is behaving strangely. Here is the code.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main (void) {
printf("What is the card number?");
long long card = GetLongLong();
if(card <= 0)
[Code] .....
When I execute the program it asked for the number, but then nothing happens. Of course, my first instinct was that the program was caught in an infinite loop somehow, but could not figure out how. I commented out the while loop and the program completed (albeit returning the incorrect value), so I was further convinced that there was an infinite loop that I was not seeing. I ran the program throug gdb. Strangely, the program did not loop infinitely, instead it got to line 16 [while(card1 > 0] and then just stopped, it was not executing the next line of code at all.
View 6 Replies
View Related
Oct 4, 2013
I don't understand how my code not run.
#include "stdafx.h"
#include<iostream>
using namespace std;
struct student{
char name[30];
char birthday[20];
char homeness[50];
float math;
[Code] ....
View 3 Replies
View Related
May 24, 2013
I am having following pointer variable declaration
Code: Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos};
Here funcs is an array of pointers to functions which take double as input and gives double as output with static as storage type am I right.
View 2 Replies
View Related
Nov 22, 2012
I'm fairly new to C++ and have begun working with pointers. I wish to create am array called sigmaf_point that reads data from a text file. I have managed to get that working, but when it comes to using this pointer I come across some problems. The array is created as such:
Code:
double sigma [5];
double *sigmaf_point = sigma;
void read(double *&sigmaf_point)
string s;
ifstream Dfile;
std::stringstream out;
[Code] .....
I then create a coordinate system inside the main file, as the program I am writing is about modelling the movement of atoms, which requires you to know the coordinates:
Code:
int main();
double **coords_fluid = new double*[5000];
for (int i = 0; i < n_atoms_methane; i++) {
coords_fluid[i] = new double[4];
}
Now, the problem arises when I want to calculate a new variable as so:
Code:
for (int i = 0; i <= n_atoms-1; i++) {
sf1=sigmaf_point(coords_fluid[i][3]);
}
I get the error C2064: term does not evaluate to a function taking 1 arguments, and a red line under sigmaf_point that says it must be pointer to function type. I am a bit confused about this.
View 3 Replies
View Related
Dec 15, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#define CLASS 4
#define STUDENT 11
#define GRADE 5
[Code] ....
Giving me that error on 75:10
avesub+=grade[k];
and 90:17
donkeypunch+=grade[j][k];
not sure exactly why
View 8 Replies
View Related
Apr 19, 2014
I'm making a system like twitter for class called ShoutOut.com I want to be able to get the PublicShoutOut pointer pointed to by the start iterator and assign it to firstShoutOutToDisplay and secondShoutOutToDisplay because I need that in order to pass the pointers to one of my functions. When I step through the debugger the values in start are all default values like "" and so are the values in this->firstShoutOutToDisplay but the message that start points to is being output just fine.
EDIT: got rid of irrelevant code. Am I using the correct syntax to do this?
if (start != finish) {
//getting these because a shoutout needs to be passed to the function that displays
//options for a shoutout
this->firstShoutoutToDisplay = (*start);
[Code] ....
View 2 Replies
View Related
Mar 29, 2013
I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?
Code:
#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}
[code]....
View 4 Replies
View Related
Jun 11, 2014
I am trying to send the maximum long value through function call, but i didn't print proper value..
[
#include <stdio.h>
long long floatToInteger_old(float value){
printf("float val : %e",value);
}
int main(){
float value = 340168346567;
long long finalhexVal = floatToInteger_old(value);
return 0;}
]
my actual output is 340168346567, but it is printing 3.401683e+011 or 340168343552.000000.
how can print exact value what i am sending.
View 7 Replies
View Related
Apr 1, 2013
Here is what's up:
struct Square {int number, myClass* myclass};
int main() {
vector<myClass> classes;
myClass unrelated;
classes.push_back(unrelated);
Square newClass = {3, &classes.at(0)};
.
.
.
myClass is a class I have. Now, in the class, I have a function what_value and I need to get the classes.at(0) from the pointer to it in another function. But the problem is, how can I do it? I'm completely stumped, here's what I thought of:
newClass.*myclass.what_value();
And it I get an error from the compiler. Basically, how can I do this in another function with a pointer:
classes.at(0).what_value();
View 1 Replies
View Related
Mar 6, 2015
Here is the part of my code that I need to return two values. I am working on a roulette program and I need to return the choice and the number they are betting on. How can I use a pointer to achieve this?
Code:
int makeBet(char choice, int num){
printf("
What type of bet would you like to place? ");
printf("
Type n for number.
Type e for even/odd.
Type d for dozen.
[Code] ....
View 2 Replies
View Related
Aug 1, 2014
How to return as a pointer to a string?
View 5 Replies
View Related
Jul 30, 2014
Ok here is the code
//assuming that all the directives have been included here
void ptrPointer(vector<string>* const p, int n);
int main() {
vector<string> inventory;
vector.push_back("sword");
vector.push_back("knife");
[Code] .....
Well...my question is how come the last statement or cout statement to be accurate won't work and display? Since we can do something like this below?
string text = "some text";
string *p = &text;
cout << p;
I passed the address of the vector to the function. And then display the address. It is a pretty common operation. But it just won't work. But then we do something simple similar to that of the vector. But it works.
View 6 Replies
View Related
Nov 5, 2014
I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?
Code:
1
2
3
4
5
6
7
8
char * GetValueAtIndex(char * const c, int index)
{
int i = 0;
char *p = c;
while (i++ != index)
p++;
return p;
}
View 2 Replies
View Related
Jul 13, 2014
/*
* symboltable.c
*/
#include "symboltable.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/utlist.h"
[Code] ....
View 2 Replies
View Related
Nov 21, 2014
So I have been working my way through this assignment and I'm just stuck now. I cannot get this work properly It just tells me I'm trying to return a local variable when attempting to return postfix in the to_postfix function. It is line 97 that wont compile. Also I cannot change anything in runner.c.
Calculator.c
Code:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include "stack.h"
[Code] .....
View 11 Replies
View Related
Jun 1, 2014
Suppose i have a function:
int & f1(int & p) {
return p;
}
void main() {
int a,b;
b = 10;
a = f1(b);
a = 11;
cout<<b<<endl;
}
why when i change a, b doesnt change? a is supposed to be an alias of b right?
View 5 Replies
View Related
Mar 14, 2013
I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
Code:
position = hash->(*funcHash)(idNmbr);
The function will return an int, which is what position is a type of. When I compile this code,
I get the error: error: expected identifier before ( token.
Is my syntax wrong? I'm not sure what would be throwing this error.
View 3 Replies
View Related
Sep 26, 2013
question from chapter 11, qn 8 modern C programming by king
Write the following function: Code: int *find_largest(int a[], int n); When passed an array a of length n, the function will return a pointer to the array's largest element
Code:
#include <stdio.h>
int *find_largest(int a[], int n)
{
int i, x;
x = 0;
[Code].....
have traced the code line by line and it prints correctly up to line 31. However, when the program exits (line 35) , it goes to some other screen with very complex code and my output disappears.
Just to clarify: If I just run the code as is, there is no output. However, when I trace the code line by line, the output appears, but then disappears as the program exits My input was 1 2 3 4 5 6
View 11 Replies
View Related
Jun 29, 2014
I'm trying to write a function that returns a pointer to a dynamically allocated array. Here's my code:
#include <iostream>
using namespace std;
void IndexArray(int, int);
int main(){
int *arr, n;
[Code] ....
When I try running the program, I get the error
"Unable to start program 'D:C++FilesdynamicArraySolReleasedynamicArray.exe'. The system cannot find the file specified."
I'm honestly not sure if the issue is my program, or something with C++. At the moment, I cannot debug any of my programs or else I get the same exact error. I basically need to release everything without debugging it. I last used C++ about a year ago and I'm finally back in school, and so trying to get back into it. I use Microsoft Visual C++ 2010.
View 14 Replies
View Related