C :: Returning Back To Another Function

Mar 7, 2014

Here's a small portion of my program:

Code:
int choice(void) {
char buffer[BUFSIZ];
char answer;
printf("

[Code] .....

I am wondering which is correct to use

Code: return choice();
or
Code: choice();
return num;

View 4 Replies


ADVERTISEMENT

C :: How To Loop Back To The Beginning Of Function

Oct 11, 2014

I am writing another program and I cannot find for the life of me how to loop the program back to the start of a function.

Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int choice;
char band1, band2, band3, band4;
printf ("This program calculates the resistor value based on the colours of the wire.
(enter the integer near the command)
");
printf ("What would you like to do?

[Code].....

This is my current iteration of the program. Obviously, I haven't finished writing the case 1 of the first switch, but for the other ones. I thought that return main would cause the program to loop back to the beginning after executing the case, but I see that it is not the case (pun not intended). Anyways, what would I have to insert to cause the program to loop again (other than for case 3)? And another question, why is it that in scanf in the first case, the program only accepts two characters before finishing?

View 4 Replies View Related

C :: Function Not Sending Back Values

Nov 4, 2013

I am trying to get all these functions work together and send the value of countX and countY back into main from function2() and function3() to be used by function4() later on.. But I keep getting 0 printed out and I am not quite sure why.

Code:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}

[code]....

View 2 Replies View Related

C :: How To Make Function Which Gives Back Two Numerical Values

Nov 3, 2014

How make function which gives back two numerical values. I think needs using structure. now i try found my c book.

View 3 Replies View Related

C++ :: Pointer Function - Getting Information Back To Main

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

C++ :: Function With 3 Arguments - Bring Back New Number Generated With Replacement

Oct 26, 2014

Write a function that takes 3 arguments. The function has to bring back a new number that has been generated with the replacement of the figure that is on a given position in the number with a figure that is been transferred as an argument(have in mind that the position of the figure is being counted from right to left,starting from one). Write a main program in which the newly formed numbers will be printed for numbers of a range written by the user.

Example: if you wrote the numbers 2276,3 and 5 the function should bring back the number 2576

If you didn't understand the text, the example shows that in the number 2276, the number has been counted from right to left by the second argument "3" and in the place of the figure "2" has been put the figure "5".

This is where I got stuck, I can't figure out how to make the replacement.

int argument(int x,int y,int z) {
return 0;
} int main() {
int a,b,c;
printf("Enter a value for a(100-999):");
scanf("%d",&a);

[Code] ....

View 3 Replies View Related

C++ :: Function Returning A Value

Feb 20, 2015

I am making a game commonly know as the Hangman using C++.

Now I am trying to add a man in it like this:

0
|/
|
/

Now the problem i am facing is that i am using a check that if a function returns the value 0 "return 0" it means the guess is wrong and it will not update the man but if it returns any value there will be a function called which will update the man.

I just wanna know that how i am going to use the check, the kind of thing that i am trying to use is, in general words "if(function returns a value) then update the man"

int main() {
return match;
}

How are we going to use it in check that if int main is returning 'match' in the check...

View 3 Replies View Related

C++ :: Int Function Not Returning A Value

Jan 22, 2014

This simple little program is not returning a value. The output is

" (string) contains characters" (The number of characters is supposed to display between the 'contains' and 'characters.'

However, if I go to the function and cout the length, the cout in the main body displays just fine.

Here's the main portion :

cout << "'" << input << "' contains "; //Output of character count.
charCount(input);
cout << " characters, including any spaces.
"; //Output of character count.

and here's the function.

int charCount(char *string) {
int length = 0; //Variable to hold the number of characters.
//Gets the number of characters contained in *string and puts that number into length.

[Code] .....

View 2 Replies View Related

C :: Returning Pointer From Function

Nov 21, 2014

As the title says, i'm using a function which returns a pointer to a struct:

the struct is the following:

Code:
typedef struct POINT
{
uint16_t x;
uint16_t y;
}

Coordinate; the function i'm using:

Code:
Coordinate * Read_XTP2046(void)
{static Coordinate screen;
//calculations to determine the coordinates
screen.x=(temp[1]+temp[2])/2;
screen.y=(temp[0]+temp[2])/2;
// and so on...
return &screen;}

The question is: how do i catch this pointer and make it into a Coordinate struct in which i can read the x and y.

In my main program i would do the following:

Code:
Coordinate cor;
cor = Read_XTP2046();

This does not work, as the function returns a pointer, but how to transform this pointer into a Coordinate struct.

View 8 Replies View Related

C :: Returning Function To Array?

Mar 31, 2013

I need to create a function which will print a list from 100Hz to 1000Hz then 1000Hz to 9000Hz. I have created a function in order to calculate and set up the frequency values from 100Hz to 9000Hz using two for loops as shown below. However I am unsure how to return this to the array at the main.

int main(void) {
double Frequency[18];
system ("PAUSE");
return(0); } double Frequency (void)
{
int count;

[Code]....

View 1 Replies View Related

C :: Returning Value From One Threaded Function To Another

Apr 15, 2013

I am using two threads and i want to take value of a function from one thread and use it in other. I am not good at the concepts of threads. Here is the following code:

Code:
void ThreadA(void const *argument){
uint32_t status = I2S002_FAIL;

status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A);
if (status != DAVEApp_SUCCESS) {

[Code] ....

So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...

View 1 Replies View Related

C++ :: Why Function Is Not Returning Integer 1 Or 0

Nov 14, 2013

why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/

#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));

[code].....

View 2 Replies View Related

C++ :: Expression - Value Returning Function

Dec 17, 2014

How is the definition of the term "expression" affected by value returning functions, and why?

View 5 Replies View Related

C++ :: Returning Dynamic Value From A Function

Nov 10, 2014

Is this considered a memory leak?

Polygon* create_square(const Vector2d& position, const RGB& colour, const std::string name) {
// Polygon, Vector2D, RPG and Vertex2d are structs with public data members only
Polygon *temp = new Polygon;
temp->name = name;
temp->colour = colour;
temp->position = position;
temp->vertices = new Vertex2d;
return temp;
}

View 1 Replies View Related

C++ :: Returning Array From A Function?

Jun 17, 2013

I am trying to neaten my code by putting them in different cpp files but in one function an array is changed:

int function(int array2[100][9])
{
for (int i =0; i < 100; i++)

[Code]....

View 9 Replies View Related

C++ :: Returning By Reference From Function

Feb 15, 2015

#include<iostream>
using namespace std;
int &fun() {
int x = 10;
return x;
}
int main() {
fun() = 30;
cout << fun();
return 0;
}

The code outputs 10.

Shouldn't it show an error because x is created locally on stack and gets destroyed on function return?

View 1 Replies View Related

C/C++ :: Returning A String From A Function?

Mar 23, 2015

#include <stdio.h>
#include <conio.h>
#include <string.h>

[Code].....

The code above is my attempt. If I can get the above code to work

View 5 Replies View Related

C++ :: Function Not Returning Value (Int Data)

Sep 27, 2013

I have a function, which has to return some int data. In that function there are multiple return statements. There is also possibility that function may return in some cases. Will this result in undefined behavior???

View 3 Replies View Related

C/C++ :: Function Isn't Returning A Vector

Nov 11, 2014

I am writing a function to take two vectors and put them end to end in a third vector. I'm new to working with vectors, and I cannot figure out why my append function is not returning vector C. I had the function print out vector C within it to make sure the logic in the function wasn't the problem, and it worked perfectly. My code is as follows:

#include <iostream>
#include <vector>
using namespace std;
//append function to put vector b after vector a in vector c
vector <int> append(vector <int> a, vector <int> B)/>/>/> {
vector <int> c;

[code]....

and my output is as follows:

Vector A contains: 10 18 123 172
Vector B contains: 283 117 17

The two vectors back to back are:

Obviously, the third vector is not returning from the function to main properly, but why.

View 5 Replies View Related

C/C++ :: Returning Two Numbers Of A Function

Apr 14, 2014

I'm trying to solve some problems in c that i read in internet as the following example.

Make a program who receives a int number n>0 and returns how many digits of n, and the first digit of n.

View 13 Replies View Related

C :: Returning Char Array By Function

Mar 2, 2015

I'm having trouble returning a char array by a function, here's the code. The problem is the 'reverse' function, the purpose of the function is to send two char arrays, 'newline' containing the char array, reverse it and place it in the 'rev' char array then output it back in main, however the output remains blank so I assume there must be something wrong with the reverse function.

Code:
#include <stdio.h>
#define MAXLINE 10
int fgetline(char line[], int maxline);
void copy(char to[], char from[]);
void reverse(char forw[], char rev[], int arrsize);

[Code] .....

View 1 Replies View Related

C++ :: Returning Short Int Array In A Function

Feb 14, 2014

I'm trying to return a short int in a function..This is my function signature :

short int* StartRecord(int seconds)
this is my array :
short int waveIn[NUMPTS];

I'm trying to get the data into an array :

short int arr [] = StartRecord(3);

getting this error: Error2error C2440: 'initializing' : cannot convert from 'short *' to 'short []'

View 1 Replies View Related

C++ :: Boolean Function Not Returning False

Mar 24, 2014

I have a bool type function and set it to explicitly return false, but I am still getting true as the return.

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
double coeffs[3];
double roots[2];

[code].....

View 7 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C++ :: Returning A Pointer To 2D Array From A Function

Dec 10, 2014

I know how to pass a 2-D array to a function. The prototype for that is void f(int (*p)[2]) assuming the array is of integers and there are 2 columns in it.

However, if I wanted the same function to return a pointer to a 2-D array, what would be the prototype?

View 2 Replies View Related

C++ :: Write A Function Returning 2 Values?

Jul 23, 2013

So I have a function like the one below

bool get_array( float input_param, vector<int>& output_param ){
// some code that handles output_param output
if( error ) return false;
}

So basiclly this function must return 2 value well one of the value is just a bool returning whether the procedure doesn't fail at some point or not.

is there any better way to write this function ?

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved