C/C++ :: How To Get Formation From Pointer Function To Main Function
Feb 13, 2014
int example (int [], int, *int,*int,*int,*int);
int main () {
My code will be here
example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work
[Code] ....
View 2 Replies
ADVERTISEMENT
Feb 6, 2014
I am trying to make a information to pointer function but the problem is how/what number am i putting in for *a...
And can i get that information back to main? and is that right way to split the array in to ? because i have will 200 random number and I need to find the smallest and second smallest element in array.
two_smallest (print, size3,size3,size3,size3);
} void two_smallest (int find_array[] , int size3, int *a, int *a2, int *b,int *b2) {
for (int index = 0; index <= 100; index ++) {
if (find_array[index] < find_array [0]) {
find_array[0] = find_array [index];
*a = find_array[0];
[Code] ....
View 1 Replies
View Related
Dec 22, 2014
I have int pointer called p and i want to calculate average.Since average involves using double or float so i am trying to convert this in the function averagetemp. It still gives me an error saying "cannot be converted"...
#include <iostream>
using namespace std;
int* createArray(int n);
int lowesttemp(int *p,int f);
int highesttemp(int *p,int f);
double averagetemp(int *k,double f);
void print(int *p,int lowest_temp,int highesttemp,int average_temp);
[Code] ....
View 8 Replies
View Related
Aug 2, 2014
I have the following:
int Allocate(int, int *);
main() {
int *Pointer;
int Elements = 25;
// this works just fine - as expected.
Pointer = (int *) malloc(Elements, sizeof(int));
// This DOES NOT - The value of Pointer never changes.....
[code]....
View 2 Replies
View Related
Sep 14, 2013
I am getting a few compile errors for what might be a simple thing to do. I am opening a file in main, passing that pointer to a function and checking the contents of that file with a regex before I pass it on to build a BST. I am getting the following compile errors, what is wrong. Here are the errors:
Code:
gcc main.c fileCheck.c -o tree
main.c: In function `fileCheck':
main.c:19: error: syntax error before "FILE"
fileCheck.c: In function `fileCheck':
[Code] .....
Fatal error: Command failed for target `tree' Here is the two files and header that seem to be causing me the problems.
main.c
Code:
#include "main.h"
//#include "node.h"
int main(int argc, char *argv[])
FILE *fp;
if (argc > 2)
[Code] ....
And the header file.
main.h
Code:
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
[Code] .....
View 2 Replies
View Related
Mar 16, 2013
What would be the correct way to call a function within main that has file pointer parameters?
function prototype: Code: void CalculateBoth(int num1, int num2, int*sumPtr, int *diffPtr);
View 2 Replies
View Related
Aug 12, 2013
I know what are pointer's and how to use them but there is one point i am not able to understand. Below is the example code
I understand everything in the below code except 1 thing why i am using pointer to base class object in vector int the main() Function?
Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// base class
[Code] ...
Here is the lines of code i want to understand.
Code:
vector<Employee*> employees;
employees.push_back(&emp1);
employees.push_back(&mgr1);
I know if i will not use the pointer base class function "virtual double grossPay" will be called for both base class object and derived class object and when i will use pointer with reference to the object because base class function is virtual it will look for same function in derived class and if available it will execute it.
View 3 Replies
View Related
Jun 4, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
[Code].....
View 2 Replies
View Related
Jun 4, 2013
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
int main(void) {
double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
double TC[4][4];
transpose(C, TC);
[Code] ......
View 2 Replies
View Related
Jan 19, 2013
Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {
[Code].....
But when I try to call it, trying to copy my previous method,
glutKeyboardFunc(Player1.playerControls);
I get an error
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.
View 2 Replies
View Related
Jun 9, 2013
The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
Code:
#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {
[Code].....
View 4 Replies
View Related
Dec 26, 2014
I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .
By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..
Code:
int main (int argc, char *argv[]){
//get_parameter_value(argc,argv);
// buffer[packet_size+1]= char ("'");
while (argc > 1) {
if (argv[h][0] == '-')
[Code] .....
View 3 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
Feb 16, 2013
I am getting call of nonfunction in function main <> error and 's' is assigned a value that is never used in the function warning...
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
float a,b,c,s,area;
[Code] ....
View 3 Replies
View Related
Apr 24, 2014
Why the value does not return; Here is code
#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int getUserChoose (int);
[Code] ....
here is the output
Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C
View 5 Replies
View Related
Jan 24, 2013
If so what is the reason, and the returning int value indicates wat?
View 4 Replies
View Related
Jan 30, 2014
I'm currently writing a poker game and am trying my best to avoid using global variables. I have a few variables in int main() which i was hoping to use to store the value of each players hand. I then created a function which calculates the value of the hand but cannot get this value back into the main function.
For example:
Code:
#include <iostream>
using namespace std;
void getValue(int value) {
value = 4;
[Code] ....
Is there any way i can get the value of value using this function? If not what can I do?
View 8 Replies
View Related
Mar 30, 2014
i would like to know if i need to dynamically allocate a string in main before passing it to a function that i have created.
in that function i just read the string and do not change any chat in it.
View 2 Replies
View Related
Nov 8, 2013
This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//prototype functions
void menu();
[Code] .....
So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.
View 6 Replies
View Related
Feb 9, 2013
I am just practicing some recursion and I am having trouble with printing out a recursive function in main. Here is what I have:
Code:
// This function adds the squares 4, 5 = 4*4 + 5*5 recursiveley
int recursive_sumSquares(int m, int n) {
if (m < n) {
return m*m + recursive_SumSquares(m+1, n);
}
else {
return m*m;
[Code]...
I am getting an error that says undefined reference to 'recursive_SumSquares'
View 2 Replies
View Related
Aug 17, 2013
I have i want to call a function with two results for example x = 1 and y = 2.How do i return this function in c and how do i call such a function in the main program.
View 9 Replies
View Related
Sep 8, 2014
I know how to define a shape and attach it to a window as follows:
#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");
Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}
But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it to be visible on window win?
View 4 Replies
View Related
Sep 17, 2013
I don't exactly know how to test my ==friend function in my main.
Here is my .h file:
#include<iostream>
using namespace std;
class Car{
public:
Car();
Car(int yer, string mke);
[Code] ....
View 3 Replies
View Related
Feb 25, 2013
Get user input should be done in a function. The function should read the product number, price per unit, and quantity sold and return them to the main().
Display the value of product number, price per unit and quantyty sold in main().
View 7 Replies
View Related
Mar 5, 2014
I have simple LCd_call function . I am calling this function from main . I wanted to call this function once. problem i am facing here, When lcd_call function being called. It enter the cases but instead of staying paricular case it coming back and starting case 1 iteslf . for every 6s it change the case to 1:
View 2 Replies
View Related
Sep 8, 2014
I know how to define a shape (here, a rectangle) and attach it to a window in C++ as follows:
#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");
Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}
But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it on the window win to be visible?
View 4 Replies
View Related