Well the cost of living in Brazil depends on a lot of things but specially about the region of the country where you plan to spent some time.
How you might know Brazil is a large country, then, if you apply yourself doing researches I'm sure that you'll find a nice and cheap place.
I would recommend you to search some universities at São Paulo or another big state such as Rio de Janeiro and Rio Grande do Sul. These states have what we call "global cities" and they're also well developed as big cities around the world.
Safety in Brazil is a polemic question. Yes, it is true that this country isn't the safest place of the world but come on, people sometimes say too much! It isn't the worst place ever either...
I do believe that you can protect yourself from violence avoiding dangerous places doing simple things like... Avoiding contact with strangers, always being near from someone that you can trust and who knows where he or she is, keeping some emergency phones with you for some emergency, easy things like that..you know?
Like I said, I can suggest you to access sites from some colleges, www.mackenzie.com.br is my university and is located in São Paulo, where I live. There are some exchange programs to foreigners but honesty I don't know in fact how it really works. If you got interested and have some doubt fell free to contact me..
I wish you a lot of lucky in your new experience!