Passing Args Error

This is a discussion on Passing Args Error within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    36

    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.

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>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 :-)
    *Cela*

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    36
    ah, so now I know why I couldnt get programs to work with accepting pointers to arrays explicitly.

    thx

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>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;
    }
    *Cela*

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You only really want a pointer to an array when the array should be a specific size.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21