C++ :: Why Can't Void Be Returned

Apr 22, 2012

Why is it not okay to return void? Most compilers will probably let you (gcc does) but it gives you a warning that you aren't supposed to. Most languages allow you to return void.

Something like

Code:
void log(const std::string & txt){ std::cout << txt << std::endl; }
//C++ way to do it
void bar(int i){

[Code].....

View 10 Replies


ADVERTISEMENT

C++ :: Error With Value Being Returned

Nov 18, 2013

I am working on my final project for my class and after finally getting it to compile with no errors to finding examples/tutorials and following skeleton code I cam encountering a problem.

The program runs, asks all the correct questions but when it displays the base pay and total pay for all 3 employees it comes back as ( -1.0743 blah blah )

When they work over 40 hours it works correctly but when they work under 40 hours it displays those weird numbers in those sections.

// Kevin Johnson -- Overtime Pay -- Final Assignment
// Created 11/14/2013 // Edited 11/17/2013
#include "stdafx.h"

[Code]....

View 9 Replies View Related

C++ :: How To Use The Value Returned From Int Type Function

Aug 28, 2014

I have this int type function that returns a number. It returns the value 2 for now but later it will return more variety of values. How do I use the value it returned? I'm not sure of the proper syntax.

View 5 Replies View Related

C :: Quadratic Equation - ID Returned 1

Oct 18, 2013

This is my code:

Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation

[Code] ......

And I keep getting this error:

Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status

View 5 Replies View Related

C :: Same Error Returned For All Code

Mar 11, 2014

I've had with visual studio but nothing seems to be working. No matter what I do even with simple programs, like Hello World, I'm always getting an error about a .pch header file.fatal error C1083: Cannot open precompiled header file: 'DebugConsoleApplication1.pch': No such file or directory

This is only for one of the programs I've made but I'm pretty new to programming and I've not even used the header files for anything so I have no clue how to resolve this problem.

View 2 Replies View Related

C/C++ :: Indices Returned In Bsearch

Jul 14, 2014

I have some struct which contains: void *elems (basically a pointer to an array of contiguous memory).

I want to use bsearch to return a pointer, and then somehow figure out where in the array that value is. Having a pointer in this case isn't enough, I need to know what the index is. I've tried a number of things:

int index;
void *value = bsearch(key, start_ptr, cv->count, cv->elemsz, cmp);
index = &value - &start_ptr;
return index; [
Replacing the second line with:

// in the first instance
index = (char*) value - (char*) start_ptr;

// in other instances...
index = ((char*) value - start_ptr))/cv->elemsz)

But nothing works.

View 6 Replies View Related

C :: How To Save Returned Of Unknown Length

Sep 15, 2014

I call a function that returns a string, and I can print it out fine, but I want to test the result of the function to see if it returns 0. But I can't just call the function again (GetNextToken(b)) because it will generate a different token. I can't allocate space for the string because I'm not sure what the size of the returned string is going to be.

Basically I want to see if the GetNextToken(b) returns 0, and if it doesn't then print the string. And running GetNextToken(b) again will give a different result.

Code:
int main(int argc, char **argv) {
SomeStruct* b = CreateStruct(argv[1],argv[2]);
printf("HERE %s", GetNextToken(b));

View 3 Replies View Related

C :: How To Get Address Returned By Malloc Function

Dec 6, 2013

So, I'm in the midst of implementing my own malloc() and free() functions, but I'm having a hard time with the syntax of getting the address that malloc returns. Whenever I check the address, it's 0 Here's the code:

Code:
char *word = malloc(10);
int address = *word;
printf("%d",address);

The reason I want the address is so that I could store it in a data structure for further usage when I'm dealing with different cases for the free() function. Or is there another way to do this?

View 5 Replies View Related

C++ ::  Returned Temporal Objects Lifetime

May 4, 2014

What does the C++ standard say about returned temporal objetcts's lifetime ?For example, in this code:

#include <iostream>// Object cout, manipulator endl
using std::cout;
using std::endl;
class C {
private:

[code]....

Here, the temporal object C returned by function f() still lives when function h() is called and is destroyed inmediately after function h() returns to his caller (the function main()). So, it seems that a returned temporal object lives while it is used and it is destroyed when not used (in the next sentence of the sentence that call the function that returns the temporal object). Does the C++ standard specify that this must be the behaviour of C++ compilers?

View 1 Replies View Related

C# :: Deserialize Returned XML Data From Web Service

May 16, 2014

I'm trying to read a data returned from a web service. How i could extract the juice of this document in c#?

Here's the code

<?php
require_once("nuSOAP/lib/nusoap.php");
//require_once("Classes/Connection.class.php");
//require_once("Classes/Customer.class.php");
require_once("includes/config.php");

[Code] ....

How will i extract the result from the Array Customer?

View 2 Replies View Related

C# :: How To Count Number Of Rows Returned By SQL

Jan 29, 2014

I want know if the query returned zero rows or not.

Don't want to use count(*)

sql = "select * from TABLE where employeefirstname = @First order by EmploymentStatusDescription";
using (SqlCommand cmd = new SqlCommand(sql, conn)) {
cmd.Parameters.AddWithValue("@First", First);
reader = cmd.ExecuteReader();
} while (reader.Read())

View 7 Replies View Related

C/C++ :: Time Unit Returned From GetProcessTimes

Jan 25, 2014

I have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?

View 3 Replies View Related

C/C++ :: Store Returned Array From A Function

Feb 12, 2014

I am just trying to make a simple two player game. First player enters the movie and second player guesses it by using some basics of C++.

movie[] = entered by player 1.
movie_temp[]= a temp array with '_' in it. It updates after every guess by player 2.

MY PROBLEM: Please refer the main function where I called the function movie_check().

This updates the life after every guess. I want the same to happen for my movie_temp array.

When i run this program, only the lives are updated properly, on correct guess the lives are not reduced, but in next turn the array_temp is not updated and the same array is displayed again and again after each gas.

How to create a function which return array and save it in movie_temp (just as I did for life).

IDE: Code::Blocks
Compiler: GCC Compiler

#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>

void display_movie(char movie_temp[], int);
void display_life(int);
int win_player2(char movie_temp[]);

[Code] ....

View 4 Replies View Related

C/C++ :: Time Difference Returned In Seconds

Mar 6, 2015

I need to get the current time, have the system sleep for a period of time, then return the difference in seconds.

#include <iostream>
#include <string>
#include <ctime>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace::std;
// in the <ctime> library is a function time(0)

[Code] ....

I'm not receiving an errors but the return value is not correct. It's returning 1.4259 no matter how long it sleeps for.

View 2 Replies View Related

C++ :: How To Check Result Returned From Iterator

Feb 7, 2012

Code:
it = m_CoopTable->m_SparseMap.find(s);
if (it != NULL) //Error
{
return false;
}

This gives me compile-time error. it is an iterator to a hash_map

View 9 Replies View Related

C++ :: Random Crashes With Process Returned -1 (0xFFFFFFFF)

Jun 30, 2013

I randomly get this when I execute my program. Sometimes it happens three times in a row sometimes it can go about 10 times before it shows up again.

I was not able to find out what the error code means, and I can't pinpoint the error. During debugging it NEVER happens, and logging tells me it happens between two cout << operations.

what the error code means?

View 12 Replies View Related

Visual C++ :: Const Char Returned By Various Functions

May 13, 2013

What is the programmers responsibility with respect to const char * returned by various functions, like the C++ string class c_str() function which returns a const char * to an c style string array? In VC++ I cannot delete a const char * which holds a string literal. Take the following code for example:

Code:
void func() //a useless function with illustrative code {
string s1("abcd");
string s2("efgh");
const char * cc1 = s1.c_str(); //c_str() returns a const char * c style string pointer
s2.c_str(); //this returns a const char *, which must be allocated on the heap right?
delete cc1; //produces run time error in Release mode in VC++
}

The problem with the above code snip is that space is allocated on the heap (or so I believe) for the const char *'s returned by the 2 calls to c_str(). The delete attempt fails and there is no opportunity to delete the space allocated by const char * because its not assigned to anything (however I see c_str() used this way extensively)

So, if I cannot delete a const char *, how does the memory get recovered? Perhaps the string objects s1 and s2 themselves have pointers to the items on the heap made by c_str() calls and they get deleted by the destructors of s1 and s2 when the function ends?

View 3 Replies View Related

C++ :: Permission Denied Error - ID Returned 1 Exit Status

Jul 13, 2014

I'm new to C++ and keep getting an error. I get a permission denied and id returned 1 exit status, the code is fine and as far as i understand this would be because my OS doesn't allow modification of currently running files which would make sense as when i look in task manager it shows my program running even though it has finished. Ending process/process tree does nothing as does using any third party process terminator.

There is no loop in the program or anything even a simple hello world program yields the same result. Only way i can re-run my program is restarting my computer or saving the project under another name and re-compiling...

View 4 Replies View Related

C++ :: Graphics H Library - Error ID Returned 1 Exit Status

Mar 19, 2014

I am trying to compile a program with the graphics.h library included but I always get this error:Id returned 1 exit status.

View 1 Replies View Related

C++ :: Function Should Not Display Anything But Resulting String Is Returned As A Result

Mar 2, 2014

c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:

A function recive: "housesinkbuildings" .The function returns: "house=sinkb=uildi=ngs" in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.

View 2 Replies View Related

C++ :: Void Value Not Ignored As It Ought To Be

Feb 8, 2013

The error is coming up in line 13(srand() issue I think) of the following code:

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]){

[Code] ....

I'm sure it's something really simple that I'm overlooking.

View 2 Replies View Related

C++ :: Error - Void Value Not Ignored As It Ought To Be

May 4, 2014

Using a template in the assignment, I don't know what I did wrong?

Code:
#include <iostream>
#include <string>
using namespace std;
template<class T>
void mpgcalc(T& Miles, T& Gallons)

[Code] .....

View 2 Replies View Related

C++ :: Have To End A Program In A Void

Jul 16, 2014

I have a void that needs to end a program but a break and return 0 both won't work. Instead I have it cout (1/0). It works but is there an alternative?

#include <iostream>
#include <thread>
#include <Windows.h>
#include <limits>
using namespace std;
double clicks=0;
double result;
bool gameon=false;

[Code] .....

View 3 Replies View Related

C++ :: Use The Void Pointers?

Nov 25, 2013

how can i use the void pointers? i understand that can recive an adress variable(&). but can recive a value?

Code:
int a=5;
void *d;
b=&a;
b=100;//???

why i can't do these?

View 14 Replies View Related

C :: Memcpy Between Void Pointers

Feb 13, 2014

I am trying to add data to a queue with the following simplified code:

Code:
typedef struct Queue {
void * data;
int head;
int tail;
int elementSize;

My question is, how do I move the queue->data pointer to the correct memory location in order to copy given data to head? The code above inside memcpy gives med the error: "expression must be a pointer to a complete object type".

Do I need an extra pointer to be able to navigate between the queue's head and tail, and keep queue->data as a reference to the first byte of the allocated memory, or is it possible with only queue->data?

Edit. Just noticed I have mixed up head and tail. The enqueued data should probably go to the Queue's tail and not the head. However, the problem is still the same.

View 2 Replies View Related

C :: Dereferencing Of Void Pointer

Apr 14, 2014

I could understand void pointers I created the following program:

Code:
#include <stdio.h>
#include <string.h>
int main(void) {

char word[] = "Zero";
int number = 0;
void *ptr = NULL;

[Code] .....

The program works fine, however i really want to fully understand what is going on with the dereferencing of the void pointer, for example: With the following code:

Code:
ptr = &number;
*((int *)ptr) = 1;

Why can't you just do:

Code:
ptr = &number;
*(int *)ptr = 1;

And again with this code, (i'm guessing it's becuase its a pointer to a pointer?):

Code:
ptr = &word;
strcpy(ptr,"One");

View 2 Replies View Related







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