I'm working on Project Euler 22. I think I got the logic and my code is a step away from the answer. But something creepy is going on.
Basically I have four functions: "read" to read the input of names, "swap" to swap two character strings, "sort" to sort an array of character strings in alphabetical order, "worth" to calculate the worth of a name.
I ran into two troubles:
(1) If you notice, my "sort" function actually sort the array in reversed alphabetical order. When I tried "if(strcmp(names[j-1],names[j])>0)", it gives "Illegal instruction: 4". Why is that so?
I can still continue with the reversed sorting. But the second problem is weirder.
(2) At the very last step, I need to define an integer "sum" to record the total name scores. But when I defined "int sum=0", the array names[] is shifted! names[1] becomes names[0], names[2] becomes names[1], and so on. How did this happen?