P
Pete
Can someone please help, I'm trying to pass an array to a function, do some
operation on that array, then return it for further use. The errors I am
getting for the following code are, differences in levels of indirection, so
I feel it must have something to do with the way I am representing the array
in the call and the return.
Below I have commented the problem parts.
Thanks in advance for any help offered.
Pete
#include <stdio.h>
#include <string.h>
char P10(char key[]); /* prototype */
void main()
{
char key[20];
int i;
printf("\nEnter a 10 bit Binary Sting: ");
gets(key); /* Copy representation of 10 bit binary string
entered from keyboard to key[]. "not to use for binary operations
just representation */
/* below I'm getting an error 'char[]' differs in levels of indirection to
'char'
and '=' left operand must be l-value */
key = P10(key); /* function call. copy returned array into key[] */
printf("Key is now : \n");
for(i=0; i<10; ++i) { /* loop to print returned array key[] */
printf("%c\n", key);
}
}
char P10(char Ctext[]) { /* Trivial function to permute input string */
int Perm10[10]={3,5,2,7,4,10,1,9,8,6};
int i;
int index;
/* Trace statement checking key[] has been passed */
for(i=0;i<10;++i) {
printf("Ctext = %c\n", Ctext);
}
/* Trivial Permutation function */
for(i=0; i<10; i++) {
index = Perm10;
printf("index = %d\n", index);
Ctext = Perm10[index-1];
}
/* Below shows the error 'return' : 'char' differs in
levels of indirection from 'char *' */
return Ctext; /* return Ctext[]/key[] to calling function */
}
operation on that array, then return it for further use. The errors I am
getting for the following code are, differences in levels of indirection, so
I feel it must have something to do with the way I am representing the array
in the call and the return.
Below I have commented the problem parts.
Thanks in advance for any help offered.
Pete
#include <stdio.h>
#include <string.h>
char P10(char key[]); /* prototype */
void main()
{
char key[20];
int i;
printf("\nEnter a 10 bit Binary Sting: ");
gets(key); /* Copy representation of 10 bit binary string
entered from keyboard to key[]. "not to use for binary operations
just representation */
/* below I'm getting an error 'char[]' differs in levels of indirection to
'char'
and '=' left operand must be l-value */
key = P10(key); /* function call. copy returned array into key[] */
printf("Key is now : \n");
for(i=0; i<10; ++i) { /* loop to print returned array key[] */
printf("%c\n", key);
}
}
char P10(char Ctext[]) { /* Trivial function to permute input string */
int Perm10[10]={3,5,2,7,4,10,1,9,8,6};
int i;
int index;
/* Trace statement checking key[] has been passed */
for(i=0;i<10;++i) {
printf("Ctext = %c\n", Ctext);
}
/* Trivial Permutation function */
for(i=0; i<10; i++) {
index = Perm10;
printf("index = %d\n", index);
Ctext = Perm10[index-1];
}
/* Below shows the error 'return' : 'char' differs in
levels of indirection from 'char *' */
return Ctext; /* return Ctext[]/key[] to calling function */
}