A
arnuld
Its an array of pointers (to chars). Program compiles fine
PURPOSE: To print the values that array elements point to.
CURRENT STATE: Nothing is getting printed.
#include <stdio.h>
void swap_elements(char* , char* );
void print_array(char** p);
int main(void)
{
char* arrp[4] = {0};
char a = 'a';
char b = 'b';
char c = 'c';
char* pa = &a;
char* pb = &b;
char* pc = &c;
arrp[1] = pa;
arrp[2] = pb;
arrp[3] = pc;
print_array(arrp);
/* printf("Swapping Elements ....\n");
swap_elements(arrp[1], arrp[3]);
print_array(arrp);
*/
return 0;
}
void swap_elements(char* p, char* q)
{
return;
}
void print_array(char** arr)
{
char* p;
for( p = *arr; p; ++p)
{
printf("Element: %c\t", *p);
}
printf("\n");
return;
}
======================= OUTPUT ==========================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra test.c
test.c:35: warning: unused parameter ‘p’
test.c:35: warning: unused parameter ‘q’
[arnuld@dune programs]$ ./a.out
[arnuld@dune programs]$
PURPOSE: To print the values that array elements point to.
CURRENT STATE: Nothing is getting printed.
#include <stdio.h>
void swap_elements(char* , char* );
void print_array(char** p);
int main(void)
{
char* arrp[4] = {0};
char a = 'a';
char b = 'b';
char c = 'c';
char* pa = &a;
char* pb = &b;
char* pc = &c;
arrp[1] = pa;
arrp[2] = pb;
arrp[3] = pc;
print_array(arrp);
/* printf("Swapping Elements ....\n");
swap_elements(arrp[1], arrp[3]);
print_array(arrp);
*/
return 0;
}
void swap_elements(char* p, char* q)
{
return;
}
void print_array(char** arr)
{
char* p;
for( p = *arr; p; ++p)
{
printf("Element: %c\t", *p);
}
printf("\n");
return;
}
======================= OUTPUT ==========================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra test.c
test.c:35: warning: unused parameter ‘p’
test.c:35: warning: unused parameter ‘q’
[arnuld@dune programs]$ ./a.out
[arnuld@dune programs]$