I'm new to stack overflow as well as C programming. I was trying to create txt .file to store my telephone number as a list in to the text file. I will first ask them to enter the details and that details will then store into the txt file. I having trouble with an error, saying my variable is "uninitialized". What should I do?
here's my code
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
void assignEmpTelNum();
void searchEmpTelNum();
void updateEmpTelNum();
void empTelNumByDept();
void main()
{
system("tds");
printf("*****Telephone Directory System*****
");
printf("1. Assign Telephone Number to New Employee
");
printf("2. Search Employee's Telephone Number
");
printf("3. Update Employee's Telephone Number
");
printf("4. View Employee's Telephone Number by Department
");
printf("5. End System
");
printf("Enter your option: ");
int option;
scanf_s("%d", &option);
switch (option)
{
case 1:
assignEmpTelNum();
break;
case 2:
searchEmpTelNum();
break;
case 3:
updateEmpTelNum();
break;
case 4:
empTelNumByDept();
break;
case 5:
exit(0);
default:
main();
}
}
void assignEmpTelNum()
{
FILE* fp;
fp = fopen("tel.txt", "w");
system("tds");
printf("*****Employee Details and Assign Telephone Number*****");
printf("
Employee Name: ");
char emp_name[30];
scanf_s("%s", emp_name);
printf("
Employee ID: ");
char emp_id[5];
scanf_s("%s", emp_id);
printf("
Employee's Telephone Number: ");
int emp_num;
scanf_s("%d", emp_num);
printf("
Employee's Department: ");
char emp_dept[50];
scanf_s("%s", emp_dept);
fprintf(fp, "%s %s %d %s
", emp_name, emp_id, emp_num, emp_dept);
fclose(fp);
printf("
*** PRESS ANY KEY TO CONTINUE ***");
getchar();
main();
}
The error list
question from:
https://stackoverflow.com/questions/65887454/i-have-a-problem-with-storing-data-in-to-my-text-file-using-c 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…