Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function parameter 1

Status
Not open for further replies.

Leibnitz

Programmer
Joined
Apr 6, 2001
Messages
393
Location
CA
what should to be the proper parameter for the function "Break" in the program below.

#include <iostream.h>
void Break( char **number );
void main()
{
int *iNumber[15];
for( int j = 0; j < 5; j++ )
{
for( int k = 0; k < 15; k++ )
{
cout<<&quot;Enter a number: &quot;;
cin>>iNumber[j][k];
}
}
Break( iNumber );// what should be the parameter here ?
}

void Break( char **number )
{
for( int i = 0; number != '\0'; i++ )
cout<<number<<&quot;,&quot;;
}

&quot;iNumber&quot; alone doesn't work.
i'am trying to call the function &quot;Break&quot;,i can't seems to found the correct way to write the parameter for that function.


Any help will be very apreciated !
 
Thanks for the sugestion,it works,however i will like to know how i should correct the parameter in this code:

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define _MAX_ARRAY_ 11
#define _MAXSIZE_ 1000
int BreakNumber( char* num, char** Part );
void main()
{
long number = 0;
char *fnumber = new char[_MAXSIZE_];
char *snumber = new char[_MAXSIZE_];
char (*part)[_MAX_ARRAY_];
char *tmp = new char[_MAX_ARRAY_];
puts(&quot;Enter a number: &quot;);
gets( fnumber );
int size = strlen( fnumber );
int x;
if( size != 0 && !( size % 9 ))
x = size/9;
else
x = size/9 + 1;
part = new char[x][_MAX_ARRAY_];
int last = BreakNumber( fnumber, part ); // i'am geting a mistake here
for( int i = 0; i < last; i++ )
{
cout<<&quot;part[&quot;<<i<<&quot;] = &quot;<<part;
if( i != last )
{
cout<<endl;
if( i == 9 )
cout<<endl;
}
}
cout<<endl;
delete fnumber;
delete [] part;
delete tmp;
}

int BreakNumber( char *num, char **Part )
{
int j = 0, k = 0, z = 0;
while( num[j] != '\0' )
{
if( z != 9 )
{
num[z] = num[j];
z++;
}
else
{
num[z] = '\0';
strcpy( Part[k], num );
k++;
z = 0;
}
j++;
}
num[z] = '\0';
strcpy( Part[j], num );

return k;
}

I'am geting this error:
cannot convert parameter 2 from 'char (*)[11]' to 'char ** '

Thanks in advance to anybody who can help me with this !
 
Hi Laibz,

I think you can declare function with char **;

BreakNumber(char **p) =======> Is Okay

But you can't call it with
char m[_MAX_ARRAY];

So do it for solution

BreakNumber(char *p[_MAX_ARRAY])

And It will Allow you to pass array.
 
Sorry I missed something

Your declaration.
BreakNumber(char **p)
But you can't call it with
char m[_MAX_ARRAY];

So do this for solution

declare...
BreakNumber(char p[][_MAX_ARRAY])

And It will Allow you to pass array.
 
Thanks for the reply,it works !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top