This is due to format specifier %char
. It is not a valid format specifier, there is no such thing as %char
that C understands.
Make a habit of standard library reading man pages of the functions that you are planning to use. For example, scanf
. Read through Conversions section of that man page. That will guide you about what format specifiers are to be used with scanf()
.
Look at the variable there:
char name;
Its a char
, it can only hold one character.
To store a name, I assume that you need more than one char
. So you might want to use an array of characters.
So, change it to:
char name[MAX_LENGTH_NAME]; //MAX_LENGTH_NAME can be a macro set to some value, example 32?
And change your scanf()
call for worker name to,
scanf("%s", name); // Note: `&` is gone here!
Getting the return values from scanf()
, and adding some error handling for unexpected return will save you a lot of pain going ahead.
The printf()
says, its a program to calculate something for 10 workers,
for(i=0;i<=10;i++)
This loops for 11 iterations, not 10. I hope you aren't the 11th worker :-).
Change it to for(i = 0; i < 10; i++)
.
Additionally, conio.h
is non-standard. If you are developing on a platform that mandates you using this header, you may want consider switching to a better development environment. For example, a linux machine with a bash terminal and a standard gcc compiler.
Lastly, void main
is bad, use int main(void)
instead. To know more on why, read What should main() return?
Irrelevant: GUI Design and what messages you throw up on console are very crucial going ahead. He
is strictly masculine :D Aren't there any women workers around? It could be way better if you start printing the name instead of He
.