Create a File & write Data in it in c

 #include<stdio.h>

int main()

{

  FILE *ptr;

  

  char  name[20];

  float  salary;

  

  ptr = fopen("Emplyee.txt","w");

  

   if (ptr == NULL)

    {

        printf("File does not exist.\n");

        return 0;

    }

  

  printf("Enter the name of the emplyee 1: \n");

  scanf("%s", name);

  fprintf(ptr, "Name  = %s\n", name);

  

  printf("Emplyee1 salary\n");

  scanf("%f", &salary);

  fprintf(ptr, "Salary  = %.2f\n", salary);


  printf("Enter the name of the emplyee 2: \n");

  scanf("%s", name);

  fprintf(ptr, "Name  = %s\n", name);

  

  printf("Emplyee2 salary\n");

  scanf("%f", &salary);

  fprintf(ptr, "Salary  = %.2f\n", salary);

 

  fclose(ptr);

  

  return 0;

}

Comments

Popular posts from this blog

create a num table in a new file in c

write a programme to compare time stamp in c

write a struct programme to keep bank details in c