C++ :: How To Return Value Of A By Calling Function Loop
May 29, 2014
Suppose I have the following function containing while loop:
#include <iostream>
using namespace std;
int Loop () {
[Code]....
here in above code I want to return value of 'a' by calling function 'Loop'. Is there any way to do this??
for above code output should be:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
View 8 Replies
ADVERTISEMENT
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
Apr 18, 2013
I am having a problem with a program. I have a bunch of classes all derived from the same base class. I want to loop through a vector of objects, calling a function in each. The problem is that it doesn't matter which class the objects are, only the function defined in the base class is called.
I simplified the code as far as possible to replicate the problem. As you see, I would like a mix of numbers 1,2,3 as the output, however using the vector the only number output is 1. Here is a copy of the output by the way:
base->num() : 1
a->num() : 2
b->num() : 3
(*it)->num() : 1
(*it)->num() : 1
(*it)->num() : 1
I suspect this is the "slice" problem, because the vector is defined with pointers to the base class so it uses the base class functions? The question is how to get around it? How can I loop through a vector of objects sharing the same base class but calling each by their correct member functions?
Code:
#include <iostream>
#include <vector>
class Base {
public:
int num() { return 1;}
[Code] .....
View 5 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
Feb 21, 2013
How would I go about getting a loop to return to the start?
View 2 Replies
View Related
Mar 19, 2013
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.
View 2 Replies
View Related
Oct 18, 2014
I need a few pointers on how to replace the multiple "return input" in my "choice" function with a statement that perform the same action in C Programming..
Code:
/*
*FILENAME:
*PROJECT:
*PROGRAMMER: Brian Hinds
*DATE: September 05, 2014
*DESCRIPTION: This program uses a function to calculate the result of raising one number to the power of another.
[Code] ....
View 1 Replies
View Related
Nov 10, 2014
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]...
View 1 Replies
View Related
Feb 19, 2014
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!
View 5 Replies
View Related
Mar 20, 2013
I need to create a loop to return a minimum value using a boolean variable but don't quite understand how to format my algorithm.
#include <iostream>
using namespace std;
int main() {
bool first = true;
while (first) {
cout << "Enter a number (X to exit): ";
int num;
[Code]....
I know its jacked up any comments in the code would be great I need to finish the program but also understand it.
View 6 Replies
View Related
Apr 6, 2014
I am currently having problems creating a loop that will allow my user to choose to return to the beginning of the program or quit.
#include <iostream>
using namespace std;
int main() {
int j;
do {float a;
cout << "+----Welcome to Basic Operations----+
| Select Your Operation |
[Code] .....
I have not yet finished designing the interface for a couple of the operations, but right now i am hung up on trying to return to the beginning. I believe it is because the j was defined inside do and isn't carried out of the do statement for while.
View 13 Replies
View Related
Jun 8, 2014
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?
View 7 Replies
View Related
Aug 3, 2013
Every 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] .....
View 5 Replies
View Related
Jul 2, 2014
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].....
View 3 Replies
View Related
Apr 3, 2013
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).
View 2 Replies
View Related
Dec 28, 2013
I want to call the array from one function to another all function not a main function
View 2 Replies
View Related
Apr 6, 2012
I 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
View 2 Replies
View Related
Oct 24, 2013
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] ....
View 2 Replies
View Related
Feb 20, 2013
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] ....
View 2 Replies
View Related
Oct 13, 2014
We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.
View 11 Replies
View Related
Sep 12, 2013
I'm new to C/C++. I'm trying to make a program that's going to use the CBLAS libraries that I downloaded on BLAS. After fighting tooth and nail with VC 2005 (I downgraded on purpose because at one point I was desperate.) with regards to solving compilation errors and such and eventually it all compiled just fine.
The problem now is, I get the above mentioned error. It says: "Unhandled exception at 0x0040271c in Try.exe: 0xC0000005: Access violation reading location 0x4e18feb8."
Now there are a few .cpp files (I'm compiling as C code.) which contain the functions and there is one other one which contains my main method. Using the debugger, it goes through 3 files all in all.
The main file: Code: /* cblas_example2.c */
#include <stdio.h>
#include <stdlib.h>
#include "cblas.h"
#include "cblas_f77.h"
[Code] .....
I get the above-mentioned exception in the last line, or:
Code: cblas_dgemm( UNDEFINED, transa, transb, *m, *n, *k, *alpha, a, *lda, b, *ldb, *beta, c, *ldc );
The debugger tells me what the address in the exception is the address if *ldc.
View 6 Replies
View Related
Dec 19, 2013
Expected output: 20
But what I got is: 22
Why. While calling sub function it should take the global variable am I right
insert Code:
#include <iostream>
using namespace std;
int a=0;
void sub()
[Code] ....
View 3 Replies
View Related
Mar 7, 2014
Code:
const MenuData breakfast[NUMOFBREAKFASTITEMS] = {
{"Egg Breakfast", "Two eggs with a side of bacon and two slices of toast.", "", "2 Eggs, 2 Toats, 2 Bacons", "", 250.00},
{"Pancake Breakfast", "Three Buttermilk pancakes served with butter and syrup.", "", "Three Pancakes, Butter, Syrup", "", 200.00},
[Code]....
What I'm trying to do is call the printReceipt function in the main, but I'm doing it wrong. Here is my attempt.
Code:
printReceipt (const MenuData menu[], qty, info)
I've tried it many other ways but I keep getting an error. I tried researching it on the internet, but I don't get much info.
View 14 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
Nov 2, 2013
I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.
#include<iostream>
#include<fstream>
using namespace std;
void bubbleSort();
void selectionSort();
[Code] .....
View 1 Replies
View Related
Dec 29, 2012
I'm trying to call a function on a derived class that's in a vector of it's base class. I've made the code really simple for illustration purposes:
class Sprite {
virtual void update();
}
class Enemy : public Sprite {
virtual void update();
[Code] ....
I want to be able to just call update() on the items in the vector and the derived class update() functions be called. Currently, it always calls the Sprite update, which makes sense, but it's not what I want. Is there a way to call the derived update function without knowing the type of the derived class?
View 6 Replies
View Related