I am from Peru. I have flight within 24 hours to Madrid and I do not have C-1 visa. I heard from some friends that they have entered US and paid for a Visa in the airport and did not have problems. I wonder if someone can share their experience or suggest a solution.
This is unfortunately not possible. The US does not issue visas on arrival, and the airline most likely won't let you board the plane without one.
Peru is also not a VWP country so you won't be able to use an ESTA instead of a visa.
Given how soon your flight is, you won't be able to get a visa in time so the only option is to change your flight.
Edit: as jcaron mentioned in a comment, any other valid US visa you might have can also be used for the purpose of transit, if you happen to have one.