Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

How to parse an array C++?

Status
Not open for further replies.

FboDigit

Member level 1
Joined
Jun 19, 2012
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Canada
Activity points
1,502
Hi all, I used to be good at programming in C but I didn't pratice since a lottt of years so I need a little ramp up

I want to parse an array but I am not able to do it and I feel really noob !!

Code:
[B]IN THE .h[/B]
...
   void Test_I2C(int);
...



[B]IN THE .CPP[/B]

int *csv_array[5]; //is it good ???
	int i;
	for(i=0 ; i<sizeof(csv_array)/sizeof(*csv_array);i++) //this is good
	{
		useless code for the example
	}

MyFunct(csv_array[i]); //is it good ?

void MyFunct(.......) ///what to put here
   ...
   var = csv_array[1];
   ...
Also if you have a better//easyer way to do it (with pointer or struct) I would really appreciate the help
Please help !!!
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
Re: Parsing an array C++

int *csv_array[5]; //This is an array of pointers to ints.

for(i = 0; i < 5; i++)

MyFunct(csv_array); //The argument of the call is a pointer to an int

void MyFunct(int *ptr) ///what to put here, an int pointer
{
int value;

value = *ptr;
 

FboDigit

Member level 1
Joined
Jun 19, 2012
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Canada
Activity points
1,502
Re: Parsing an array C++

Hi btbass !
Thx for the answer but I got 2 error while doind this.
The first compilation error is : 'main::my_funct' : cannot convert parameter 1 from 'int *' to 'int'
and the second is error C2511: 'void main::my_funct(int *)' : overloaded member function not found in 'main'

I really don't understand the meaning of those warnings

Regards

EDIT :Is there a way to use a specific memory space with *ptr ?
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
Re: Parsing an array C++

It sounds like you have defined the function with an int as the argument and not an int pointer.

void my_funct( ? )

Are you sure you need an array of pointers to int?
Why not just an array of int?
 

FboDigit

Member level 1
Joined
Jun 19, 2012
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Canada
Activity points
1,502
Re: Parsing an array C++

Hi btbass
Of course only an array of int would be enough!

I have done this:
Code:
void my_funct(int[]);
...
void main
{


int csv_array[5];
for(...){
}
...
my_funct(csv_array[]);  [U]// Line 69 [/U]


void my_funct(csv_array[5])
{
...
}
But the compiler say

'error C2059: syntax error : ']' on the line 69

I don't want to lose any more time on this I only want to parse an array as a variable.
Thanks for your help
 
Last edited:

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
Re: Parsing an array C++

my_funct(&csv_array[0]); /* pointer to start of array */

void my_funct(int *array)
{
int a, b;

a = array[0];
b = array[1];
...
}
 

FboDigit

Member level 1
Joined
Jun 19, 2012
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Canada
Activity points
1,502
Re: Parsing an array C++

Thanks you btbass it is working !!!!
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top