Is there someone who can assist me with this? It skips over the Name:, It will not ask for your name. | Sololearn: Learn to code for FREE!

0

Is there someone who can assist me with this? It skips over the Name:, It will not ask for your name.

#include <stdio.h> #include <stdlib.h> struct employee{ int employee_ID; char name[50]; char address[50]; double salary; }; int main(){ struct employee EmployeeInfo; FILE *fptr; char store[] = "Information.txt"; printf("########## Create a file (Information.txt) and input employee information ##########\n\n"); fptr = fopen(store, "w"); if(fptr == NULL){ printf("Error!"); exit(1); } printf("Employee ID: "); scanf("%d", &EmployeeInfo.employee_ID); printf("Name: "); fgets(EmployeeInfo.name, sizeof EmployeeInfo.employee_ID, stdin); printf("Address: "); fgets(EmployeeInfo.address, sizeof EmployeeInfo.address, stdin); printf("Salary: "); scanf("%lf", &EmployeeInfo.salary); fprintf(fptr, "Employee ID: %d\n", EmployeeInfo.employee_ID); fprintf(fptr, "Name: %s", EmployeeInfo.name); fprintf(fptr, "Address: %s", EmployeeInfo.address); fprintf(fptr, "Salary: %.2f", EmployeeInfo.salary); fclose(fptr); printf("\nThe file %s created successfully!", store); return 0; }

5/22/2021 7:09:42 AM

Trisha Kled

5 Answers

New Answer

+3

I edited your code and commented some of the problems. The input prompt still improperly displayed in console but now name & address are read in as expected. https://code.sololearn.com/cn582wMKv2nt/?ref=app

+3

You're welcome Trisha, Anyways, I noticed you have reposted this problem, and it's okay cause it's not completely solved. But I would recommend you to save your code in SoloLearn, and share the saved code link (in the new thread) instead of raw text code like we have here. People are more keen to look into saved code because there'll be no need to copy/paste before they can analyse the code (less hassle). Here's how we share a saved code link, in case you didn't know https://www.sololearn.com/post/75089/?ref=app

+2

Trisha, I have updated the code, and the prompts works fine when I tested it.

+1

Yes, before the name appears in the code, it will ask for it. But anyhow, thank you for helping me sir!

+1

Thank you for the information sir! Im new here btw