Rewrite this program to use a function for each of the ways you’re printing out things. Try to pass pointers to these functions so they work on the data. Remember you can declare a function to accept a pointer, but just use it like an array.
How do you do? I have c code which are with for looping printing out index array and pointer index. Here right code without function:
int main(int argc, char * argv[])
{
int number[] = {123, 456, 789};
char *strchars[] = {
"ABC", "DEF", "GHI"
};
int count = sizeof(number) / sizeof(int);
int i = 0;
for(i = 0; i < count; i++) {
printf("%s has %d \n", strchars[i], number[i]);
}
// with pointers
int *po_number = number;
char **po_strchars = strchars;
// loop with pointiers
for(i = 0; i < count; i++) {
printf("%s has %d \n", *(po_strchars+i), *(po_number+i));
}
return 0;
}
But i need use for each of the ways printing out things. But I can’t figure out. Here my code with functions but without pointer and chars only integer. Give me how to make it right:
#include <stdio.h>
// void print_arg(int a[], int b[]);
// now it right?
// void print_arg(int a[], int b[])
void print_arg(int a, int b);
// or now it right?
void print_arg(int a, int b)
{
int a;
int b;
int count = sizeof(a) / sizeof(int);
int i = 0;
//and it
for(i = 0; i < count; i++) {
printf("%d and %d\n", a[i], b[i]);
}
}
int main(void)
{
int number[] = {22, 32, 22, 82, 2};
int strchars[] = {12, 12, 12, 12, 12};
int count = sizeof(number) / sizeof(int);
print_arg(number[], strchars[]);
return 0;
}
Are you trying to write a function that will print the data?