Showing posts with label Text. Show all posts
Showing posts with label Text. Show all posts

C Program To Store Students Record In A Text File

How to write a C Program To Store Students Record In A Text File in C Programming Language ?


Solution For C Program :

/*C Program To Store Students Record In A Text File.*/


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    FILE *fp;
    char another='y';
    int marks1,marks2,marks3,marks4,marks5,role;
    char name[20];
    clrscr();

    fp=fopen("Students.txt","w");
    if(fp==NULL)
    {
        puts("Cannot open file");
        exit(1);
    }
       fprintf(fp,"Role No.\tNAME\t  PHYSICS  CHEMISTRY  MATHS  S.S.T  ENGLISH\n");
    while(another=='y')
    {
        printf("\nEnter name :");
        scanf("%s",&name);
        printf("Enter your Role No.:");
        scanf("%d",&role);
        printf("Enter marks in Physics:");
        scanf("%d",&marks1);
        printf("Enter marks in Chemistry:");
        scanf("%d",&marks2);
        printf("Enter marks in Mathematics:");
        scanf("%d",&marks3);
        printf("Enter marks in Social Science:");
        scanf("%d",&marks4);
        printf("Enter marks in English:");
        scanf("%d",&marks5);
        fprintf(fp,"%d\t%s\t%d\t%d\t%d\t%d\t%d\n",role, name, marks1,marks2,marks3,marks4,marks5);
        printf("Add another record (y/n): ");
        fflush(stdin);
        another=getche();
    }
    fclose(fp);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable



C Program To Print Text Into Uppercase

How to write a C Program to print text into uppercase in C Programming Language ?

Program to Print text into Upper casing until interrupted using CTRL + Z, Program to Final Maximum of Numbers Entered until interrupted by CTRL + Z, Program to Count No of Characters until Interrupted by CTRL + Z

Program to Print text into Upper casing until interrupted using CTRL + Z

Solution For C Program :
#include<stdio.h>
void main()
{
char ch;
printf("\nPlease Enter the Data. To Stop Press CTRL+Z.\n\n");
while((scanf("%c", &ch)) > 0)
if(ch >= 'a' && ch <= 'z')
printf("%c", ch - 'a' + 'A');
else
printf("%c", ch);
}

Program to Final Maxuimum of Numbes Entered until interrupted by CTRL + Z

Solution For C Program :
#include<stdio.h>
void main()
{
int n,max=0;
printf("/nEnter the Numbers : \n\n");
while((scanf("%d", &n)) > 0)
{
printf("\nThe Given Number is : %d.\t", n);
if(max < n)
max = n;
printf("The Maximum at Present is : %d\n", max);
}
}

Program to Count No of Characters until Interrupted by CTRL + Z

Solution For C Program:

#include<stdio.h>
void main()
{
int no_chars = 0;
while(getchar() != EOF)
++no_chars;
printf("\nThe Number of Characters Entered are : %d.", no_chars);
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable