C++ :: Using API Function That Has Char Pointer As Argument

Feb 5, 2014

I am using a small robotic-car that is controlled by writing C/C++ codes under Linux. I need to use a particular function from the library provided by the manufacturer. The relevant API documentation for the function is:

BASEBOARD_ERROR_KIND ZMP zrc :: :: :: Baseboard GetRS232Data (char * msg )

RS232 data acquisition.

Argument:
[Out] msg Address of the acquired data.

Returns:
BASE_OK RS232 data acquisition success
BASE_BASE_232_GETDATA_ERR RS232 data acquisition failure

I have trouble writing the relevant code in the main program that invokes this function. Here is a snippet of what I have tried:

# include "Baseboard.h"
int main () {
Baseboard _Baseboard; // Class name is Baseboard
char *msg ;

[Code] ......

The part where I am uncertain is how to handle the char pointer "msg" in the declaration, function call and referencing. According to the documentation, the char pointer "msg" is the output of the function so I presume that is is somehow dynamically allocated. Am I handling the char pointer properly in the declaration, function call and referencing parts?

Another related question I have is: I am printing out the value of the variable "dummy". I always get 0 for it. Since the variable "dummy" is an enum of type BASEBOARD_ERROR_KIND which can take on two values (first value represents success and the second failure), it is alright to get a integer value of 0 for it if the function call was successful ? (I do not have much experience with using enums so this is a enum-related question on whether we can get an integer value representing the first enum value) .

View 2 Replies


ADVERTISEMENT

C++ :: Void Pointer Argument In A Function?

Jun 11, 2014

Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?

Code:
#include <stdio.h>
int compareid(void* info, int value); // ansi declaration
int compareid(void* info, int value)

[Code] .....

View 5 Replies View Related

C++ :: Function Having Argument As A Pointer Passed By Reference

Dec 8, 2014

I have to write an example in which you use a function having as argument a pointer passed by reference in C++. Can you provide an example like this:

funz.h : void funz( int *&a );
funz.cpp : ? (1)
main.cpp:
#include "funz.h"
#include <iostream>

[Code]...

as I write in (1) and (2) ?

View 5 Replies View Related

C++ :: Passing A Function Pointer As Template Argument To A Class

Aug 15, 2012

I have in the past written code for templated functions where one function argument can be either a function pointer or a Functor. Works pretty straightforward.

Now I am in a situation where I am actually trying to pass a function pointer as template argument to a class. Unfortunately this does not work, I can pass the Functor class but not the function pointer. Below code illustrates the issue:

Code:
#include <string>
#include <iostream>
#include <sstream>
#include <cstdlib>
// For demonstration
const char * external_library_call() {
return "FFFF";

[Code] .....

The idea is to have the definition of the Record class simple and readable and have a maintainable way to add auto-conversion functions to the class. So the lines I commented out are the desirable way how I want my code to look. Unfortunately I could not come up with any way that was close to readable for solving this.

View 3 Replies View Related

C :: Passing Argument Of Incompatible Pointer Type - Warning In Function Call In Main

Jun 4, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;

[Code].....

View 2 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Pass A Pointer Into Function - Value Of Char?

Jan 2, 2014

I'm having a problem understanding something with pointers. I was trying to pass a pointer into a function in MSVC-2013, like

char* charptr;
and then calling
myfunct(charptr);

and then inside the function i would set charptr equal to another char ptr, simply like

charptr = anothercharptr;

But this actually caused a compile failure in MSVC, saying charptr is being used without being initialized. in Code::Blocks it just gives buggy output.

I solved this issue by calling the function like

myfunct(&charptr);

and declaring the function like
myfunct(char**);

and then I had to dereference the charptr in the function when assigning it to another ptr, so
*charptr = anothercharptr;

It seems like you should be able to just pass a ptr into a function and change its address to that of another pointer? My main question is really, what is the value of a pointer? I thought the value of a pointer was just the memory address it contains. But then I had to reference it to pass it into the function.

What is the difference between the value of the char* charptr written as either charptr and &charptr?

View 1 Replies View Related

C++ :: Char Array Reversing Function Using Pointer?

Feb 4, 2014

Why does this code doesnt work?

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class my_string {
char* ptr;

[code] ....

View 1 Replies View Related

C :: Passing Argument 1 Makes Pointer From Integer Without A Cast

Mar 6, 2015

Code:
#include<stdio.h>
print_int_ptr(int *a){

printf(" a %i
" ,a);
printf(" &a %i
" ,&a);

[Code] .....

I get that warning : passing arg 1 of `print_int_ptr' makes pointer from integer without a cast|

View 3 Replies View Related

C :: Passing Argument 1 Makes Integer From Pointer Without A Cast

Mar 26, 2014

I am having some errors with pointers and passing arguments.

Code:

#include <stdlib.h>
#include <stdio.h>
#define MAX_FILE_LENGTH 20
typedef struct node_{
int value;
struct node_* next;

[Code]....

View 3 Replies View Related

C :: Modifying Linked List - Passing Pointer As Argument

Feb 27, 2015

I am having trouble modifying a linked list. I am writing a function to delete the last node from the linked list, but it gave me incompatible types error.Here is my struct:

Code:
typedef struct PCB{
int id;
struct PCB *next;
struct PCB *prev;
}PCB_rec, *PCB_p;

Here is my function to delete the last node (given the pointer is pointing at the last node of the list):

Code:
void del_last_node(PCB_p *process_list){
PCB_p temp = process_list;
if (temp->prev != NULL){
temp = temp->prev;

[Code] ....

And here is how I called the function:

Code: del_last_node(&process_list);

It gives me the following errors:
initialization from incompatible pointer type at line:
PCB_p temp = process_list
assignment from incompatible pointer type at line:
process_list = temp

View 14 Replies View Related

Visual C++ :: Error C3867 Function Call Missing Argument List For Calling Thread Function

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

C :: How To Pass Main Function Argument To Some Other Function

Dec 26, 2014

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] .....

View 3 Replies View Related

C :: Calling Function Via Function Pointer Inside Structure Pointer

Mar 14, 2013

I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.

Code:

position = hash->(*funcHash)(idNmbr);

The function will return an int, which is what position is a type of. When I compile this code,

I get the error: error: expected identifier before ( token.

Is my syntax wrong? I'm not sure what would be throwing this error.

View 3 Replies View Related

C++ :: Passing Argument Into Function

May 21, 2013

How to pass an int that I got from user input into a function to use it. I am trying to print out the words to a string of numbers.

I got the input from user.
I got an absolute value of the input.
I then separate the string into individual digits and name them.
I can print these out.
Then I started my if statement by checking if the original input was zero, and if it is, printing zero and exiting.
Then I an trying to pass the digits into a switch function and this is where I go off the rails.

Code:
#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

[Code] .....

View 7 Replies View Related

C++ :: Void As Function Argument

Mar 24, 2014

I was reading about void as function argument, but I did not fully understand it's meaning in C.

In C++
void foo(void) {}
and
void foo() {}

are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means

In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?

For example.

void foo() {
printf("%d", var);
}
foo(5);

It is very unclear for me. Do this apply to main function too?

int main(void)
int main()

or can I use arguments given to int main() like given to int main(int argc, char* argv[])

View 4 Replies View Related

C/C++ :: Passing Function As Argument

Mar 11, 2015

I have two questions :

1)
#include <iostream>
using namespace std;
void func1() {
cout << "Func1" << endl;

[Code] ....

Why ptr_func1() does not work here?

IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type

2) How can i pass func1 to func2 as parameter?

I tried void func1(void* function), but I think I'm wrong here.

View 2 Replies View Related

C++ :: 2 Argument Conversion Function

Nov 26, 2012

i have used single argument conversion function which gets called in below scenario.

Code:
#include<iostream>
using namespace std;
class Demo
{

[Code]....

It is giving error "test3.cpp: In function `int main()':test3.cpp:18: syntax error before numeric constant"

But it should work as Demo d=100; works

View 3 Replies View Related

C++ :: Function That Takes Int As Argument And Doubles It?

Jan 7, 2014

Write a c++ function that takes int as an argument and doubles it.the function does not return a value.

View 5 Replies View Related

C++ :: Function Argument - Variable Is Being Used Without Initialized

Jan 27, 2015

I get an error when i try to compile this code. I tried to allocate memory in main function and that works. But why it doesn't work in function? I think that there is something wrong with function argument, but not sure.

Code:

#include <iostream>
#include <fstream>
using namespace std;
struct Word

[Code].....

View 2 Replies View Related

C :: Declaring Array Within Function Argument

Sep 14, 2013

I have a function

Code:

int exec_program(char * arguments[])
{
...
}

I can call it like this without a problem:

Code: char * uselessvariable[] = {"/bin/echo", "Testing", NULL};exec_program(uselessvariable);

However I get an error if I try to compile it like this:

Code: exec_program({"/bin/echo", "Testing", NULL});

How, in c, I can put this array inside of the argument in one line without having to name a new variable name?

View 2 Replies View Related

C :: What Does Collection Of Parameters As Argument Of A Function Mean

Aug 27, 2013

What does collection of parameters as argument of a function in C mean? Also any place I can refer to find those parameters?

Googling gives me Parameters and Arguments But not really sure whether that is what is needed.

View 6 Replies View Related

C :: Variable Function Argument Types

Jun 12, 2013

I was wondering if one could write a function that could accept one or the other variable type.

Ex: I have 2 arrays, int** and double**, and a function

Code: void PGMWrite(double** Matrix, int Matrix_dimension){.....}

Is there any way to change the function to

Code: void PGMWrite(int** Matrix || double** Matrix, int Matrix_dimension){.....}

And then have some sort of type identifier in the function that picks the correct section via an if loop? If so how, and how would I identify in the function if the input it type double or int?

View 4 Replies View Related

C++ :: Function Call Missing Argument

Jan 7, 2014

I have same type of errors in my program

#include "iostream"
#include <stdio.h>
#include <conio.h>

[Code].....

View 3 Replies View Related

C++ :: Passing Array As Argument To Function?

Feb 10, 2013

how can i pass an array as an argument to the function? in getCoin() fcn, I am supposed to pass coins array as an argument to the function. fcn prompts user to enter coin(Date, Type and Country). values entered by user are read and assigned to the coins array. I tried the code below.

//# include "Coins.h";
#include <iostream>
#include <string>
using namespace std;

[Code].....

View 4 Replies View Related

C++ :: Function With Array Object As Argument

Jan 18, 2013

I am trying to build a function with an array object as argument. Please see the following code:

// main.cpp
const int a = 10;
......
//function.cpp
void test_func(double x, array<double, a> &y) {
......
}

This code cannot be compiled because the "a" in parameter is not identified. I cannot neither put const int a as argument to the function.

Here I need "a" to control size of the array from the main.cpp. How can I make this work?

View 9 Replies View Related







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