Hello everyone, i am new here and i am looking for a little help. What i am working on is a function that will require 7 numbers inputted from a user. Then it will add a '0' before the items. Then it will return all items as a single unsigned char. For example, if the user enters: 1, 2, 3, 4, 5, 6, 7. It should return 01234567 as a single unsigned character.
I am trying to do this two ways. One was using an array. The problem is that i cannot find how to return it as a single char. I know i cannot return the array because the function will just return one item at a time. Can anyone provide some help of examples how i can accomplish this? What i have is:
I have also tried this as accepting 7 different char as seperate variables. However, once again i do not understand how to combine those into a single unsigned char. That example is:Code:unsigned char getMessageByte() { unsigned char items[7]; char zero[8] = "0"; printf("Enter a 7 digit char of 1's and 0's \n"); gets(items); //sets the parity bit strcat(zero, items); printf("%s\n",zero); return zero; }
Thanks in advanceCode:unsigned char getMessageByte() { unsigned char item0 = '0'; unsigned char item1; unsigned char item2; unsigned char item3; unsigned char item4; unsigned char item5; unsigned char item6; unsigned char item7; unsigned char total; printf("Enter a string of 7 items consisting of only 1's and 0's: "); scanf("%c%c%c%c%c%c%c",&item1,&item2,&item3,&item4,&item5,&item6,&item7); //How do you combine item0+items1-7 to total???" return total; }



LinkBack URL
About LinkBacks



