-
Passing Args Error
I am recieiving this error:
C:/Mike/Uni/216/A2/code.c:221: warning: passing arg 2 of `CheckSum' from incompatible pointer type
C:/Mike/Uni/216/A2/code.c:226: warning: passing arg 2 of `digest' from incompatible pointer type
C:/Mike/Uni/216/A2/code.c:226: warning: passing arg 3 of `digest' from incompatible pointer type
Code:
int main()
{
char file[BLOCK];
unsigned char message[BLOCK];
unsigned char messageDigest[BUFFER];
int messageSize;
FILE* check; //file to check
scanf("%s",&file);
check = fopen(file,"r");
//checksum to make sure original
messageSize = CheckSum(check,message);
rewind(check);
//digest the stuff
digest(check,&messageDigest,&message,messageSize);
fclose(check);
return EXIT_SUCCESS;
}
//with these being the calls to
void digest(FILE *check,unsigned char *MessageDigest[], unsigned char *Message[],int newsize)
int CheckSum(FILE* check,unsigned char *Message[])
I've tried it several ways an can't find the way to pass a pointer ot the function
-&message
-&message[]
-message[]
-message
all similar errors, but we need a pointer to the array to alter the data currently there.
Same with an initialize option(I havent included yet)
We dont have the option of global variables.
-
>>but we need a pointer to the array to alter the data currently there.
No you don't, arrays are automatically passed as pointers to the first item in the array. Try this to see how it works :-)
Code:
#include <stdio.h>
void f(int a[])
{
a[0] = 50;
a[1] = 60;
}
int main(void)
{
int a[2] = {0};
f(a);
printf("%d %d\n", a[0], a[1]);
return 0;
}
It prints 50 60 instead of 0 0, just what you wanted :-)
-
ah, so now I know why I couldnt get programs to work with accepting pointers to arrays explicitly.
thx
-
>>ah, so now I know why I couldnt get programs to work with accepting pointers to arrays explicitly.
You can pass a pointer to an array if you want to, but you probably wouldn't want to much :-)
Code:
#include <stdio.h>
void f(int (*a)[2])
{
(*a)[0] = 50;
(*a)[1] = 60;
}
int main(void)
{
int a[2] = {0};
f(&a);
printf("%d %d\n", a[0], a[1]);
return 0;
}
-
You only really want a pointer to an array when the array should be a specific size.