taking input from user and writing in a file in C

 #include <stdio.h>


int main(){

FILE *ptr;
float sal1,sal2;
char name1[30],name2[30];
ptr=fopen("employee.txt","w");
printf("Enter name of employe 1:\n");
scanf("%s",name1);
printf("Enter the salary of employee 1:\n");
scanf("%f",&sal1);
printf("Enter name of employee 2:\n");
scanf("%s",name2);
printf("Enter the salary of employee 2:\n");
scanf("%f",&sal2);
printf("%f %f %s %s",sal1,sal2,name1,name2);
fprintf(ptr,"%s,%f\n",name1,sal1);
fprintf(ptr,"%s,%f\n",name2,sal2);
fclose(ptr);
 return 0;
}

Comments