First, 'a' is uninitialized, but you are using it as an index. My compiler warns me about this - if yours does not, adjust its warning settings until it does, then fix any and all warnings it gives...