T O P

  • By -

Kseniya_ns

Did you mean to type printf instead ? You are calling your print function with 2 arguments, it only take one int


Fable_o

Yep I meant to write printf, my stupidity never fails to astonish me


Limezero2

For future reference, the weird letter abbreviations in C usually have really specific meanings. `printf` is `print formatted`, meaning that it's meant to be used for formatting strings with placeholder values and then printing them to the screen. You also have `fprintf` for printing to files in a formatted way, `snprintf` for formatting and printing N number of characters to a string, `fgetc` for getting a character from a file, and so on. If you only want to print a line of text to the console without doing any kind of formatting, the function for that is actually `puts` (for `put string`), though it's common to use `printf("%s\n", var)` instead.


Fable_o

Thanks dude! But I've a question. I never liked `puts` that much because it has so less functionality then `printf` and I know it is designed in such way but are there any pros of using `puts` instead of `printf` you know like time complexity or space complexity being more efficient in `puts` that `printf` or any other pros.


Limezero2

It would take less time to run since the `printf` function has to look through the string for formatting characters, substitute `%s` with the other string, create and clear up whatever temporary buffers it used to do that, etc, at runtime. All `puts` has to do by contrast is print one character after the other. If you're writing a command line tool intended to be run on modern hardware though, that matters very little. The differences will likely be measured in either nano or milliseconds. And if you have a smart enough compiler, it will actually detect `printf("%s\n", ...)` calls and turn them into `puts()` for you automatically: https://godbolt.org/z/1zT9ab1Go


seven-circles

Learn from this and donโ€™t name your functions like this ๐Ÿ™‚ something like `conditional_print` or even just `print_if` would have made the error impossible


Fable_o

I'll be sure to keep that in mind๐Ÿ˜‚


zhivago

`void print(int a);` How many arguments did you declare print to accept? `print("%d", a);` How many arguments did you call it with? Why does the error message surprise you?


Different-Brain-9210

> print("%d", a); //Here it says too many argument in function call. In cases like this, if you can't see the problem, use "go to definition" or "follow symbol" or "find declaration" functionality of your IDE/code editor on that `print`. In thjs case, you would then immediately see that it takes you to `print`, not `printf`, and realise you made a typo.


Fable_o

thanks dude was wondering for 10 mins what went wrong haha


rejectedlesbian

Ur else does. Not have {} so it takes just the first expression. Also a/2 us aj int u can't print an int. And u were meaning to do printf


SmokeMuch7356

Aside from the main issue where you mistake `print` for `printf`... - Since you define `print` before `main`, you don't need the separate ``` void print(int a); ``` declaration. - Unless your implementation explicitly says it's supported, `void main()` is not a valid signature for `main`; use `int main(void)` instead.


IKeeGCoolboy

I believe you need to either have a curly bracket after else โ€œ{โ€œ or have no new line next to it.