/**
 * CSCE 236 Embedded Systems 
 * Spring 2014
 * Homework 1, programming component
 *
 * Look for comments that include "Student Code" to indicate where you
 * should fill in code.
 **/

#include <stdio.h>
#include <string.h>


/**
 * Return your user name
 **/
char* getFullName(void){
  ////////////////////////// Student Code //////////////////////////
  //  Write code to return a pointer to a _global_ variable that
  //  contains your full name.
  
  return "tbd";
}

////////////////////////// Student Code //////////////////////////
// Write a funciton called getLastName() that returns a pointer to the
// same _global_ variable that contains your full name, but that
// starts at your last name.
//



/**
 * Returns the most common letter (a-z) in string str of length
 * len. This function is case _insensitive_ (e.g. Alberta should
 * return 'a' and a count of 2). Also returns in count the number of
 * that letter found. In case of ties, return the letter closest to
 * 'a' that has the highest count.
 **/
char getMostCommonLetterInStr(char *str, int len, int *count){
  ////////////////////////// Student Code //////////////////////////
  // Write code to determine the most common letter in string s
  // DO _NOT_ just return a hard-coded number.
  // DO _NOT_ use strchr, strlen, or equivalent string.h functions to
  // determine this.
  // Instead you should write your own code to count the number of 
  // letters found. 

  return 0;
}



/**
 * Print the results of the string operation tests
 **/
void stringOperations(void){
  char *name = getFullName();
  char commonLetter;
  int commonLetterCount;

  printf("Name: %s\n",name);
  commonLetter = getMostCommonLetterInStr(name, strlen(name), &commonLetterCount);
  printf("Most common letter in full name %c, count %d\n",commonLetter, commonLetterCount);

  ////////////////////////// Student Code //////////////////////////
  // Uncomment the following code once you create the getLastName() function
   /*
  printf("LastName: %s\n",getLastName());
  printf("Initials (w/ getLastName): %c.%c.\n",getFullName()[0],getLastName()[0]);

  commonLetter = getMostCommonLetterInStr(getLastName(), strlen(getLastName()), &commonLetterCount);
  printf("Most common letter in last name %c, count %d\n",commonLetter, commonLetterCount);
   */



  printf("\n");
}

/**
 * Print the output of numious bit operations
 **/
void bitOperations(void){
  int numA = 0x53B19;
  int numB = 0xA5DE7;

  ////////////////////////// Student Code //////////////////////////
  // Complete the following print statements by outputting the value
  // after doing the bit operations indicated in the comments.  You
  // should not permanently  modify the value of the variables.

  // Output the value (1 or 0) of bit 16 (zero referenced) in numA and numB
  printf("Bit 16 in numA: %#x\n",
           numA);
  printf("Bit 16 in numB: %#x\n",
           numB);

  // Output the value of numA after setting bit 4 (zero referenced) to 1
  printf("Bit 4 set to 1 numA: %#x\n",
           numA);

  // Output the value of numB after setting bit 8 (zero referenced) to 0
  printf("Bit 8 set to 1 numB: %#x\n",
           numB);
  
  // Output the value of the numB after setting the 4-7 bits
  // (inclusive, zero referenced) of numB to the lower 4 bits of numA.
  printf("numB after...: %#x\n",
           numA);

  // Output the value of the numA after setting the 5-9 bits
  // (inclusive, zero referenced) of numA to the 4-8 bits of numB.
  printf("numA after...: %#x\n",
           numA);
  
}

/**
 * Main function that calls the corresponding functions
 **/
int main(){
  printf("CSCE 236 HW1 Output\n");
  printf("-------------------\n");
  stringOperations();
  bitOperations();

  return(0);
}
