The most likely cause of your problem is you are trying to place and run multiple small programs in one Xcode project. Each program has its own main
function, but a C program can have only one main
function. If you add three files to your project, intending each file to be its own program, and try to run the project, Xcode doesn't know you want to run only one of the files. It assumes you want to run all the files, sees you have three main
functions, and generates a link error.
Xcode is designed to have one program per project, no matter how small the program is. If you are learning C and writing multiple small programs, you have the following options:
- Create one Xcode project for each program.
- Create one Xcode project and add a target for each program. Use the jump bar in the Xcode toolbar above the code editor to choose the target to run.
- Create one Xcode project and use the target membership checkboxes on the right side of the project window to tell Xcode which files/programs you want to build and run.
- Use a text editor like VS Code, TextMate, or BBEdit to write your code instead of Xcode. I know TextMate comes with a bundle to run your programs from inside the editor. VS Code probably has an extension that allows this as well.