saving . . . saved Regarding Assignment has been deleted. Regarding Assignment has been hidden .
Regarding Assignment
Title
Question
I don't understand what is wrong with the following code. Please help.

<span style="color: #0000ff;">#include</span> <span style="color: #0000ff;"><</span><span style="color: #a31515;">stdio.h</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;">#include</span> <span style="color: #0000ff;"><</span><span style="color: #a31515;">string.h</span><span style="color: #0000ff;">></span>

<span style="color: #0000ff;">struct</span> employee
{
<span style="color: #0000ff;">char</span> name[<span style="color: #09885a;">100</span>];
<span style="color: #0000ff;">char</span> address[<span style="color: #09885a;">100</span>];
<span style="color: #0000ff;">char</span> desgn[<span style="color: #09885a;">100</span>];
<span style="color: #0000ff;">float</span> salary;
};

<span style="color: #0000ff;">int</span> main()
{
<span style="color: #0000ff;">struct</span> employee details;
printf(<span style="color: #a31515;">"Please enter the full name of the employee : "</span>);
scanf(<span style="color: #a31515;">"%[^</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">]s"</span>, details.name);

printf(<span style="color: #a31515;">"</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">"</span>);

printf(<span style="color: #a31515;">"Please enter the address of the employee : "</span>);
scanf(<span style="color: #a31515;">"%[^</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">]s"</span>, details.address);

printf(<span style="color: #a31515;">"</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">"</span>);

printf(<span style="color: #a31515;">"Please enter the designation of the employee : "</span>);
scanf(<span style="color: #a31515;">"%[^</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">]s"</span>, details.desgn);

printf(<span style="color: #a31515;">"</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">"</span>);

printf(<span style="color: #a31515;">"Please enter the salary of the employee : "</span>);
scanf(<span style="color: #a31515;">"%f"</span>, details.salary);

printf(<span style="color: #a31515;">"</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">"</span>);
printf(<span style="color: #a31515;">"</span><span style="color: #ff69b4;">\n</span><span style="color: #a31515;">"</span>);

printf(<span style="color: #a31515;">"PAY SLIP"</span>);
printf(<span style="color: #a31515;">"This is to certify that Mr/Ms. %s ,who lives at %s, works in our company as the %s. He receives %f only, as salary per month."</span>, details.name, details.address, details.desgn, details.salary);

<span style="color: #0000ff;">return</span> <span style="color: #09885a;">0</span>;
}

C-and-Cpp Working-With-Structures 05-06 min 40-50 sec 24-10-20, 11:48 p.m. bsscharan

Answers:

I believe the way you are taking the input is not okay. Please try adding & in your scanf statements, as given below:

scanf("%[^\n]s", &details.name); 


24-10-20, 11:57 p.m. sudhakarst
Sorry sir, 'copy and paste' is giving here like that. If you see there are scanf statements in the above code. Please use the following link for my code:

<Please copy and paste the following code in a browser to access my code and run it.>
https://repl.it/@coder746/Details-of-an-Employee-Assignment#main.c

I have commented some of my other doubts in the code, sir. Please check them also.

The problem is, I am not able to enter the address and designation of the employee as user input.
Thank you

25-10-20, 12:44 p.m. bsscharan

Login to add comment


Log-in to answer to this question.