C :: Function Calling In Main Program
Aug 17, 2013I 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 RepliesI 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 RepliesThe 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].....
I believe I have the syntax correct but I'm having difficulty calling my overloaded == operator in main (last snip-it of code). Below are several files explaining the code.
Commission.h here is where the friend bool operator == exists and I believe I have it initialized correctly.
#ifndef COMMISSION_H_INCLUDED
#define COMMISSION_H_INCLUDED
using namespace std;
class Commission {
public:
Commission();
Commission(int, double, double, double );
~Commission();
[Code] .....
I would like my program to display other functions in the int main function. For example, this is what my program looks like:
int Function1(int &var1, int &var2, int &var3) {
cout << "blah blah blah" ;
cin >> var1 ;
var2 = var1 * 3 ; //example
var3 = var1 * var2 ; //example
if(blah blah blah)
[Code]...
i have this program I am working on and it seems to crash after the function call getdata()
here is the code
#include<iostream>
#include<string>
#include<cstdlib>
[Code].....
I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.
void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)
[Code] ....
The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:
output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);
How to get the numbers of the main function to show up with the stars of the previous function.
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.
I searched the web for error: C3867... and the discussions where murky or obscure.
My code excerpt is:
#pragma once
#include <windows.h>
#include <stdlib.h>
#include <process.h>
void PutUpfrmIO(void *);
namespace WordParsor {
[Code] .....
I get the generic message:
error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.
One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.
Here is a sample of my question
class Base{
public:
int getNum();
private:
int numToGet;
}
class Derived: public Base {
public:
friend ostream& operator<<(ostream& output, const Derived &B);
[Code]...
Is this possible?
int myfunc( int a, int b, char * c )
char a = "(int)myfunc()";
char b = "(int,int,char*)"
call(a, b, ...) // Function name and return type, params
I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!
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] .....
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] ....
I have this sample code, that calls a function in a DLL. The function Callback is provided to the DLL as an argument, in order for the DLL to notify my program of relevant changes.
sample:
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <winbase.h>
#include "TcAdsDef.h"
#include "TcAdsApi.h"
using namespace std;
void _stdcall Callback(AmsAddr*, AdsNotificationHeader*, unsigned long);
[Code] ....
I would like to change this code, so that there is a Main class that opens the connection and there are several separate classes (as below) that register themselves for a specific variable and get notifications if that value is changed. The reason for this is that I want to get several notifications for several independent events and I don't want them to mix. I figured this should look something like this:
class.h
#ifndef INACLASS_H
#define INACLASS_H
#include "Main.h"
class InAClass {
public:
InAClass(Main* mainClass, std::string iolocation);
[Code] ....
Unfortunately this gives me an error:
error: cannot convert 'InAClass::Callback' from type 'void (InAClass::)(AmsAddr*, AdsNotificationHeader*, long unsigned int)' to type 'PAdsNotificationFuncEx {aka void (__attribute__((__stdcall__)) *)(AmsAddr*, AdsNotificationHeader*, long unsigned int)}'
At first I thought this was because I don't have the namespace "using namespace std;" on top, but then I should be able to find something that specifically needs to come from the std namespace and is not marked as such. I don't want to rule the option out, but so far I could not find anything like that.
An alternative explanation might be that the Callback function needs to be global, but if I make it global, how can I distinguish between several Callback functions?
I need to split my main() function into two separate functions.Where would the best place be to split it up?
* Read a text file whose name is given on the command line, and for each word:
* if it is an integer, insert it into an array in sorted order
* if it is not an integer, insert it into an array of words.
* Notes: converted to use C++ strings, because C strings are messier.
* Need to grow arrays, need to insert in sorted order.
* Growing arrays might be done the way we grew a C string:
* bigger = new <type> [size+1]
* for(i=0; i<size; i++) {
* bigger[i] = oldarray[i];
[code]....
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
If so what is the reason, and the returning int value indicates wat?
View 4 Replies View RelatedEvery time I try to use the function SaveNewCD, it doesn't write to file correctly. It writes the ~, three characters, then goes into an infinite loop.
#include<iostream>
#include<fstream>
using namespace std;
int SaveNewCD();
int OpenCD();
int main() {
char ArtistName[25];
[Code] .....
I am trying to call a function through a variable
The error
|error: no match for 'operator=' (operand types are 'std::string {aka std::basic_string<char>}' and 'void')|
|warning: statement has no effect [-Wunused-value]|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
#include <iostream>
#include <fstream>
[Code].....
I am trying to use ofstream to write in a txt file in a function called recurrently. for a simplified example:
void func_write(double x) {
ofstream myfile;
myfile << "the result = " << x << endl;
} int main() {
ofstream myfile;
[Code] .....
To this stage, it does not work, because the myfile in func_write cannot write in the txt file opened in main function. I don't want to open, append and close the txt file each time the function is called, that will take more time to execute all (imagine with 500 calls).
I want to call the array from one function to another all function not a main function
View 2 Replies View RelatedI have a code like this below in /root_project/main.cpp:
Code:
#include "theoraplayer/TheoraVideoClip.h"
unsigned int tex_id;
TheoraVideoManager* mgr;
TheoraVideoClip* clip;
std::string window_name="glut_player";
bool started=1;
[Code] ....
and the TheoraVideoClip.h file is in /root_project/include/theoraplayer/.
Inside of TheoraVideoClip.h there is this:
Code: TheoraVideoFrame* getNextFrame();
And when I try to compile using g++ -o app main.cpp -lGL -lglut -lGLU -ltheora -ltheoradec -ltheoraenc I'm gettin this error:
main.cpp.text+0xac2): undefined reference to `TheoraVideoClip::getNextFrame()'
Ubuntu 11.10
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] ....
How would I call a string that sits within a switch loop in the main function, into a separate function?
Like this:
void statistics() {
cout << "Here are the statistics for your entry: " << endl;
cout << "
The size of your entry is " << s.length() << " characters." << endl;
}
I am calling string s from this:
switch (toupper(myChoice)) {
case 'A': cin.ignore();
cout <<"
Please enter your text: ";
getline(cin, s);
[Code] ....
I have two functions bool check_key(string cKey, string eKey) and bool check_digit(char digit1, char digit2), and I have declared both of them globally (is this the right terminology?) right after the "using namespace std;" and right before the "int main(){".
In the first one, I called the second one . But it is giving me the error: "no match for call to `(std::string) (int&)' ".
Code:
bool check_key(string cKey, string eKey) {
if(cKey!="" && eKey=="") return false;
if(cKey=="" && eKey=="") return true;
if(cKey=="" && eKey!="") return true;
if(cKey.length()!= eKey.length()) return false;
bool flag=true;
[Code] ....
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?
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.