Thread: Assistance with Char Pointers

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    9

    Assistance with Char Pointers

    Hi guys, i am looking for a little assistance. What i am trying to write is a function that will take a 7 bit character then read its binary value. It will determine if the the amount of 1's are even or odd. if odd, it will make it even by XOR 0x80.

    My code works if i have a regular char (and i get rid of all the pointer references) but in this method i am passing it via a pointer. Could someone please take a look and provide some feedback or possible solutions. When i compile i am getting:

    orig.c: In function `makeEven':
    orig.c:165: warning: `return' with a value, in function returning void

    Here is my function:

    Code:
    void makeEven(unsigned char* somebyte) {
    
    	
    	 unsigned char temp;
    	 unsigned char x;
    	 int count1 = 0;
    
    	 x = *somebyte;
    	 temp = *somebyte;
    	 //counts the 1's
    	 while (temp > 0) {
    	 if (temp & 1 == 1)
    	 count1++;
    	 temp >>= 1;
    	 
    	 }
    	 printf("\nThe Count is: %d\n", count1);
    	 if (count1 % 2 == 0){
    	 printf("\nIt is Even\n");
    	 }
    	 else {
    	 x = x^0x80;
    	 printf("\nIt is odd\n");
    	 printf("\n%x\n",x);
    	 }
    	 return x;
    
    }
    Last edited by xxrexdartxx; 10-14-2009 at 06:53 AM.

  2. #2
    Registered User matrixx333's Avatar
    Join Date
    Mar 2009
    Posts
    67
    Your function definition states that you aren't going to be returning anything

    Code:
    void makeEven(unsigned char* somebyte)
    Yet in the definition, you tell the function to return an unsigned char x.

    Code:
    return x;
    I would recommend changing the function definition to reflect the data type you are actually returning to main. Don't forget to update your function prototype also

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    9
    Quote Originally Posted by matrixx333 View Post
    Your function definition states that you aren't going to be returning anything

    Code:
    void makeEven(unsigned char* somebyte)
    Yet in the definition, you tell the function to return an unsigned char x.

    Code:
    return x;
    I would recommend changing the function definition to reflect the data type you are actually returning to main. Don't forget to update your function prototype also
    Ill give it a shot. thx.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  5. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM