C Programming on the Mac L4 - Functions

preview_player
Показать описание
In this tutorial I cover functions and how they are used in c
Рекомендации по теме
Комментарии
Автор

I will try to remember to make a point of that in a later tutorial on different functions. Thanks again for catching that

AppleProgramming
Автор

@Shazcapade Returns are just ways of giving back information that can be used later, it never prints to the console, only printf() does that. Void in this case means that after we call the PrintMessage function, we aren't going to give back information to the main function to use later. Returns are also explained in a later tutorial and explained much better if you are curious.

AppleProgramming
Автор

It's covered much later on in the course, there are many things in there that you'll understand as you go through the later lessons. A quick explanation though is that when you call this program, you could pass in arguments that your main function could then use to. If you've ever worked with terminal and run a program in there you probably passed it some arguments. Like if you call (zip -r x y) you passed the zip program 3 arguments, the zip program's main could then handle those.

AppleProgramming
Автор

@MattyJamesOliLyne It will work above the main function, but not after. The first void function is not actually a function, it just tells the compiler, "Hey, there is function called PrintMessage() later on in this c file". Usually your main.c file wants to have main as the first function you read, and later you can even put void PrintMessage() in a separate file. If you get rid of the function prototype, your main function will have no idea what PrintMessage() is and the compiler will complain

AppleProgramming
Автор

@iradhwan You brought up a great point, it is completely optional to put "( void )" in your parameters if you are going to have no parameters in your function. You CAN leave it as just void PrintMessage(); (it's just a personal choice). All the void means is no info is put into the function. However, you MUST have the void out front (ex. void PrintMessage();) because it tells the computer if it will give the function that called it back any information. Hope this helps, let me know if not.

AppleProgramming
Автор

I have decided to start learning C and have found your tutorials extremely helpful from a complete beginners perspective, especially in comparison to the majority of books out there. One question I have in relation to the video is, is it best to have the void function twice? You have in this video, once above and below the main function. I attempted it all under one function and it works correctly but I am far too unaware to know if this will have any negative ramifications.

Thank you.



MattyJamesOliLyne
Автор

@JacobEdwardH Saying they exist beforehand just lets the file know basically every function that exists (it doesn't scan down to that function and read it). The issue with just putting them before the main function is that any function can have this issue. For example, if I have functionA call functionB and functionB calls functionA, which one should I write first (see what I mean)? By setting up the function prototypes, your program will know all the functions that can be called.

AppleProgramming
Автор

Yep, that'll be great. You can pretty much build your apps on whatever you're going to be running them on.

AppleProgramming
Автор

Please let me know what you think, leave comments and rate, thanks

AppleProgramming
Автор

Thanks! this is a very helpful tutorial!

timmycrafted
Автор

@191919mm No it's ok, I kinda forgot you were on the C tutorials ;). All you need to do is send me the folder that is created when you make a new project. The best way is to right-click the folder and compress it. Then just send it to the email I gave earlier, but I'm going to be gone for the weekend so I probably won't get back to you for a while.

AppleProgramming
Автор

Huh, you can try sending me your xcode project code but I don't see how that would do anything. The only thing I can think of is that the project isn't recompiling so you just keep getting the original thing it compiled. I would try changing your code to what you want, go to Product>Clean and try running it again.

AppleProgramming
Автор

No, its when i run it, with the changes that i have made.. it does not change into how i changed it. for example, changing the 'Hello world' into anything else, without errors or mistakes... i go to the console, run it, it still shows me 'Hello world'.

ilHashemi
Автор

So in the console you don't see what you're printing? Or is it just that the console doesn't show up?

AppleProgramming
Автор

@AppleProgramming ummm what exactly do u refer to when u say codes?i am srry its my first time i've just started learning

mm
Автор

So i tried doing exactly the same as you, but nothing changes when running the console and pressing build and run. Still the same as before, no changes. Is there something wrong ?

ilHashemi
Автор

I can't remember what his issue was exactly, but I think he sent me a message and we resolved his problem. It was probably something simple though. If you want to send me a message via YT I can help you out more.

AppleProgramming
Автор

Also getting the mach-o linker error

bigobrother
Автор

int argc, const char * argv[]
what does this line of code mean ?

adammujtaba
Автор

even after typing everything correctly, i get this error-apple mach-o linker error.how to i solve this problem?

mm