Write a program to accept N names and print it. string-level access.

/* Write a program to accept N names and print it. string-level access.*/

#include <stdio.h>

void main()

{

    char st[20];

    FILE *fp;

    fp=fopen("b.txt","w");

    do

    {

        printf("Enter the name : ");

        gets(st);

        fputs(st,fp);

        fputs("\n",fp);

        printf("Enter to continue;Escape to exit\n");

    }while(getch()!=27);

    fclose(fp);

    fp=fopen("b.txt","r");

    printf("Name List :\n");

    fgets(st,20,fp);

    while(!feof(fp))

    {

        st[strlen(st)-1]=0;

        printf("%s\n",st);

        fgets(st,20,fp);

    }

    fclose(fp);

    getch();

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.