I wrote this neat little program that has global variables in it. I have been told never to use global variables. Or atleast that any time you do there is a better way that you could have and should have done it instead. I cant think of any way to reproduce this same functionality without using global variables. So I was wondering if one of you smart fellows would know how I might have have written this application differently inorder to avoid global variables.
if (input == "current") { ← Not thread safe at all. Imagine what will happens if you access input at the same moment it will be changed. You need to wrap your string in atomic or use mutexes to ensure that no races takes place. Please not thay you can add atomic only to integers and pointers.
You should avoid globals whenever possible, but I will not say that they should never be used. There is cases where using global variable is perfectly fine.