Professional Documents
Culture Documents
c code:
#include <stdio.h>
#include <stdlib.h>
int main() {
char name[50];
char regno[10];
int marks,i,n;
printf("Enter number of students: ");
scanf("%d",&n);
FILE *fptr;
fptr=(fopen("D:\\my0158assignment.txt","w"));
if(fptr==NULL) {
printf("Error!");
exit(1);
}
for (i=0;i<n;++i) {
printf("For student%d\nEnter registration number: ",i+1);
scanf("%s",regno);
printf("Enter name: ");
scanf("%s",name);
printf("Enter marks: ");
scanf("%d",&marks);
fprintf(fptr,"\nRegno: %s \nName: %s \nMarks=%d \n",regno,name,marks);
}
fclose(fptr);
return 0;
}
code screenshot:
User input/ Output screenshot:
Output file:
2. Write a C program to print the m-n lines from a file? Where m and n line numbers.
Regno: 20bci0111
Name: abc
Marks=200
Regno: 20bci0123
Name: xyz
Marks=30
Regno: 20bci0758
Name: fkuyfvjhvj,h
Marks=80
Regno: 20bce5555
Name: okaywhut
Marks=99
Regno: 20bce1152
Name: something
Marks=100
c code:
#include <stdio.h>
#include <stdbool.h>
code screenshot:
Output screenshot: