C/C++ :: Why To Use Return Type For String Function As Char

Oct 6, 2012

If we are using strcpy() for copying the string. As we are passing pointers to it It will copy the string & no need to return the string .This function will finely work with return type as void then why Ritchie has used it as char* strcpy()?

View 4 Replies


ADVERTISEMENT

C++ :: Wrong Return Type When Returning Char Array As Pointer

Apr 25, 2014

I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.

Here is a snippet:

Code: class Player
{
private:
char state[MAX_STATE_CHAR + ONE_VALUE];
int rating;
char last[MAX_NAME_CHAR + ONE_VALUE];
char first[MAX_NAME_CHAR + ONE_VALUE];
int groupNumber = NEG_ONE;
public:
char * GetFirst() const
{
return first;
}

Visual studio is saying that the return type doesn't match.

View 3 Replies View Related

C++ :: Get Return Type Of Function

Nov 21, 2012

Say I have overloaded functions with different arguments AND return types. Each set of argument has only one corresponding return type.

Code:
Vector grad(Scalar)
Tensor grad(Vector)

Later I have:

Code:
template <class T>
void test(T x) {
... Y = grad(x)
}

Then how do I automatically declare the type of Y. Do I need to make the grad function a template and specialize each of them ?

View 4 Replies View Related

C/C++ :: What Is The Default Return Type Of A Function

Jan 17, 2013

i heard that it was int but later it is deprecated , so at present what is the default return type of a function ?

View 4 Replies View Related

C++ :: Setting Function Return Type

May 28, 2012

I want my function to return the type mpz_t, but I'm not sure how?

I've tried: mpz_t MyFunction(mpz_t A, mpz_t B){}

But it didn't work, here is my code so far, I have bolded the parts of the code which are causing errors and added the errors in the comments:

Code:
#include <iostream>
#include <mpir.h>
using namespace std;
???? A(mpz_t m, mpz_t n){
mpz_t mmo; //used to store the value of m, minus one

[Code] .....

Is there a way around this?

View 5 Replies View Related

C++ :: Returning A Structure As Function Return Type

Apr 4, 2013

I am having problems with my function definition of a function that should return a structure value.

This is the error I get compute.cpp(9): error C2146: syntax error : missing ';' before identifier 's_advertisebus'

The error is on the line where I start my function definition typing my function type as a structure. A long time ago in c the keyword struct is used with the structure type like struct s_advertisebus s_readadbus(). I tried it both ways but I got errors.

// struct.h
#ifndef STRUCT_H
#define STRUCT_H

struct s_advertisebus {
int nnumberofads;
float fpercentused;

[Code] ....

View 2 Replies View Related

C++ :: Using Pointers With Function Both As Arguments And Return Type

Jan 29, 2015

I always have confusions while using pointers with functions both as arguments and as return type.

View 1 Replies View Related

C/C++ :: Get Return Type Of Function In Template Parameter

Jul 27, 2012

Is this really the preferred way to get the return type, for use in a derived class, of a function defined in the template parameter?

template<class PARAMETER> class C {
         protected:
            typedef typeof (reinterpret_cast<PARAMETER*>(0))->function() returntype;
      };  

This works just fine for me, but seems inelegant.

View 12 Replies View Related

C++ ::  Function Return Type Template Parameters Can't Be Deduced

Dec 9, 2013

I have this code:

#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;

[Code]...

and it does not compile.

The error is:

test.cpp: In function ‘int main()’:
test.cpp:20:30: error: no matching function for call to ‘func1(std::vector<int>&)’
test.cpp:20:30: note: candidate is:
test.cpp:8:45: note: template<class T, class U> std::map<T, T> func1(U)
test.cpp:8:45: note: template argument deduction/substitution failed:
test.cpp:20:30: note: couldn't deduce template parameter ‘T’

View 3 Replies View Related

C++ :: Multi Condition Function For Char Type

Jan 30, 2013

I have always written like a>='0'&&a<='9'&&a>='a'&&a<='z' in loops etc, but no more. Basically add whatever you want to condition, and if you want point a to point b just separate them with a '-' sign. Simply

while(!isCharInside(x,"|a-zA-Z0-9.*/=|-|")){/*code*/}
bool isCharInside(char check,string condition="a-zA-Z*/+=|-|0-9"){
for(unsigned int x=0,z=getLenght(condition);x<z;++x){
if(condition[x+1]=='-'&&(condition[x]!='|'&&condition[x+2]!='|')){
if(condition[x]>condition[x+2])swap(condition[x],condition[x+2]);
for(;condition[x]<=condition[x+2];++condition[x]){if(condition[x]==check)return true;};x+=2;}
else if(check==condition[x])return true;
}
return false;}

View 1 Replies View Related

Visual C++ :: How To Assign Const Char Return Value Of A Function To Label In Windows Form

Sep 30, 2013

I am a newbie to C++ and VS ++. I have created a windows form application by dragging and dropping button, label..etc. i wish label text to be appeared as return value from a function. The function returns ' const char* '.how this returned string pointer can be used to display label text.?

View 9 Replies View Related

C++ :: Need A Function To Return A String

Aug 13, 2014

I need a function to return a string..i need to pass input as "a,b,c,a,c,d,e" function should return out put as "a,b,c,d,e".

View 3 Replies View Related

C++ :: Creating A Function To Return A String

Aug 13, 2014

I need a function to return a string

I need to pass input as "a,b,c,a,c,d,e"

function should return out put as

"a,b,c,d,e"

View 2 Replies View Related

C :: Return A String To Then Call It On Main Function?

May 26, 2013

I'm trying to return a string to then call it on main function.

Code:
const char* coiso(int chave){
char str [50];
sprintf(str,"%d",chave);
char txt[50] = ".txt";
strcat(str,txt);
return str;
}
int main () {
const char* info = coiso(8);
printf("%s",info);
}

If I do a printf("%s",str) in coiso function it works but the following code doesn't work.

View 10 Replies View Related

C++ :: Use Recursion Function That Return If String Has Same Letters

Aug 12, 2013

I've to use recursion function that return if the string has a same letters:

for example: - fff = true
- fFf = false

I did this but the return answer is always: NOT!

bool iSameLetters(char str[SIZE]) {
if(str[0]='')
return true;
else {
if((str[0] && iSameLetters(str+1) == str[0]))
return iSameLetters(str+1);
return false;
}
}

View 3 Replies View Related

C++ :: Function To Return String - File Size

Feb 24, 2012

Where i can get ready function, which return string, which describe size of file?

For example
4 = 4 b
1045 = 1,01 Kb
and etc.

View 3 Replies View Related

C :: Compute Permutations Of Any String Entered - Function Will Not Return A Value

Jun 11, 2013

This is my program, for now it is intended to compute permutations of any string entered, but the function ox will not return the final x value. ox is the function that actually computes the permutations so the return of the x value is critical.

Code:
#include<stdio.h>
#include<string.h>
int ox(int x);
int main() {
int x;
char input[10];

[Code] .....

View 2 Replies View Related

C++ :: Changing Array Of Numbers Of Type Char To Type Int?

Apr 27, 2013

I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.

My current code is:

Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()

[Code]....

View 4 Replies View Related

C++ :: Convert Element Of Int Type Of Array To Char Type?

Dec 21, 2013

how to convert an element of int type of an array to char type?

View 2 Replies View Related

C/C++ :: Operate Char String To Function At Programming?

Dec 8, 2013

can I operate a char string to a function at C programming?

View 1 Replies View Related

C++ :: Unsigned Char To String And Being Passed Into Function

Mar 24, 2015

I have the following code, but it crashes on the "data = " line...

Code:
void Test(string& data) {
unsigned char* msg = (unsigned char*)malloc(MAX_LENGTH));
...
data = string(reinterpret_cast<const char*>(msg), MAX_LENGTH);
}

I know I could just return string, but what is wrong with this code that is making it crash?

View 6 Replies View Related

C++ :: Function To Change Char Array String To Lower Case

Feb 17, 2014

This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). correct this function so it converts string to lower case and doesn't get errors.

#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
void ToLower(char s[]);
int main(){
string y_n;

[Code]...

View 1 Replies View Related

C++ :: Demonstrate String Concatenation - Passing Char Array Into A Function

Oct 10, 2013

I have been assigned the following task and I am having difficulty in getting it to compile. The compiler is stopping at line 27 but I don't no what the error is.

The task is as follows:

Write two functions with the following function prototypes:

int my string len(char str[])
void my string cat(char dest[], char src[], int dest size)

Both functions should take zero-terminated strings as input. The first function should return the length of the string to the calling function. The second function should take a source and a destination string and the total size of the array pointed to by dest. It should then concatenated the source string onto the end of the destination string, if and only if the destination string has the capacity to store both strings. If the destination string does not have the capacity it should not alter either, print and error, and return to the calling function. Demonstrate the use both the above functions by using them in a program in which you initialise two character arrays with two strings, print out their length, print out the combined length, and print out the combined string

And this is my code so far:

/* A program to demonstrate string concatenation */

#include <iostream>
#include <string.h>
using namespace std;
int my_string_len(char str[]){ // function to calculate length of a chracter array
int len = 0;

[Code] ....

View 8 Replies View Related

C :: Will Return Root Statement At End Ever Return Value Other Than Value Passed To Function?

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

C++ :: Return Value For A Type Class?

Apr 25, 2014

Code:
returnType operatorOperatorSymbol (parameterList); // syntax for operator overloading
Class Fraction

public:
Fraction operator-(const Fraction& f1){
Fraction r;
return r;
}

Is this even syntactically correct? It gives me errors. Im just trying to compile it without errors. I think the function makes sense since its returning a type Class

View 2 Replies View Related

C :: Functions With Different Return Type?

Feb 26, 2015

understand the below program.

Why I'm getting output y is 6.000000

Code:
#include <stdio.h>
int square(double a);
int main()

[Code].....

View 6 Replies View Related







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