Project 2
#include <stdio.h> #include <string.h> // YAHIR LOZOYA int main( int argc, char *argv[] ) { if ( argc != 2 ) { printf ( "You must enter a single argument on the command line\n" ); return 1; // Error code for operating system } char *theData = argv[1]; unsigned int hashCode = 0; /* PUT YOUR CODE BETWEEN THIS COMMENT */ /* AND THE CLOSING COMMENT BELOW */ // loop over each char in the given input string and // update the value of the hash code based on this char int i; for ( i = 0; i < strlen(theData); i++ ) { char nextChar = theData[i]; unsigned int mask = 0xF0000000; int currentCharVal = nextChar; hashCode += currentCharVal; if(i != strlen(theData) - 1){ unsigned int shiftedBits = mask & hashCode; hashCode = hashCode << 4; shiftedBits = shiftedBits >> 10; hashCode = shiftedBits ^ hashCode; } } /* CLOSING COMMENT */ printf ( "The hash of %s = %u\n", argv[1], hashCode ); return 0; // success code returned to Operating System }
Leave a Comment