I need to create a function that will be able to to print an entire directory in C/C++.
The function will use:
void print (const phone dir[], int size){
//code
}
//print is the function name
//const phone dir[] is the array being passed as the parameter.
//int size is the other parameter which is (number of entries in directory already).
//phone is a structure that has:
char name[20];
char phone[13];
/*If you any query do comment in the comment section else like the solution*/
#include<iostream>
using namespace std;
struct phone {
char name[20];
char phone[20];
};
void print(struct phone dir[3], int size)
{
int i;
cout<<"Name\tPhone"<<endl;
for (i = 0; i < size; i++) {
cout<<dir[i].name<<"\t"<<dir[i].phone<<endl;
}
}
int main()
{
struct phone record[3]
= { { "abc", "98989898" },
{ "pqr", "12121212" },
{ "xyz", "32323322" } };
print(record, 3);
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.