A First Come First Serve Program by C#ODE Studio –
Discription –
Click Below For Program – Continue reading
Get Programs Here
A First Come First Serve Program by C#ODE Studio –
Discription –
Click Below For Program – Continue reading
As we all know that round robin is gonna be something hard for practicals. I have made a program and found a big one on internet. It is your preference to choose one. 😉
Here goes the Round Robin : Process execution in Operating System –
Click below for program – Continue reading
WRITE SOME STUDENT’S DATA INTO A FILE TO STORE IT PERMANENTLY AND AND READ THAT DATA FROM FILE:;
ANSWER:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
struct student
{
char name[10];
int s1;
int s2;
int s3;
}s[5]; //here we define structure student//
FILE *f;
f=fopen(“stdata.txt”,”w”); //” ‘w’ “ use for open a file in write mode//
int i;
for(i=0;i<5;i++)
{
printf(“\nNAME:”);
scanf(“%s”,&s[i].name);
printf(“\nMATHS MARK:”);
scanf(“%d”,&s[i].s1);
printf(“\nPHY MARKS:”);
scanf(“%d”,&s[i].s2);
printf(“\nCSE MARKS:”);
scanf(“%d”,&s[i].s3);
}
for(i=0;i<5;i++)
{
fprintf(f,”%s %d %d %d”,s[i].name,s[i].s1,s[i].s2,s[i].s3);
fputc(‘\n’,f);
}
fclose(f);
f=fopen(“stdata.txt”,”r”); //” ‘r’ “ is for open a file in read mode//
for(i=0;i<5;i++)
{
fscanf(f,”%s %d %d %d”,&s[i].name,&s[i].s1,&s[i].s2,&s[i].s3);
printf(“\nNAME=%s\tMATH=%d\tPHY=%d\tCSE=%d”,s[i].name,s[i].s1,s[i].s2,s[i].s3);
}
fclose(f);
printf(“\nPROGRAMMING @ CODE STUDIO”);
getch();
}
OUTPUT:-
How to read a c file and count the no. of blocks,header and statements ??
ANSWER:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
FILE *f;
f=fopen(“R9.TXT”,”w”);
char c;
int a1=0,a2=0,a3=0,a4=0,i=0;
f=fopen(“R9.TXT”,”r”); //here R9.TXT is pre defined file in c language//
while(!feof(f))
{
c=fgetc(f); //used to read data from file//
printf(“%c”,c);
switch(c)
{
case ‘#’:
a1++;
break;
case ‘{‘:
a2++;
break;
case ‘;’:
a3++;
break;
default:
a4++;
}
}
fclose(f);
printf(“\nHEADER=%d\tSTATEMENTS=%d\tBLOCKS=%d\t”,a1,a3,a2);
printf(“\nPROGRAMMING AT CODE STUDIO”);
getch();
}
OUTPUT:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
struct user
{
char name[10];
char pass[10];
}*u;
int i,n,t;
printf(“\nINPUT NO. OF TOTAL SETS:”);
scanf(“%d”,&n);
s=(struct user*)malloc(n*sizeof(struct user));
for(i=0;i<n;i++)
{
printf(“\nenter USER NAME:”);
scanf(“%s”,&u[i].name);
printf(“\nenter PASSWORD:”);
scanf(“%s”,&u[i].pass);
}
for(i=0;i<n;i++)
{
printf(“\nUSER NAME:%s”,u[i].name);
printf(“\n=PASSWORD:%s”,u[i].pass);
}
printf(“\nINPUT CURRENT TOTAL SETS:”);
scanf(“%d”,&t);
s=(struct user*)realloc(u,t*sizeof(struct user));
for(i=n;i<t;i++)
{
printf(“\nenter USER NAME:”);
scanf(“%s”,&u[i].name);
printf(“\nenter PASSWORD:”);
scanf(“%s”,&u[i].pass);
}
printf(“\nNEW RECORDS AFTER INITIALIZING\n”);
for(i=0;i<t;i++)
{
printf(“\nUSER NAME:%s”,u[i].name);
printf(“\n=PASSWORD:%s”,u[i].pass);
}
printf(“\nPROGRAMMING AT CODE STUDIO”);
getch();
}
We can define a pointer for a structure in the same way we declare pointers for others :
just define structure as
struct data
{
int a;
}s,*ps;
ps=&s
here we declare pointer for above data type;
enjoy the example below.
#include<conio.h>
#include<stdio.h>
struct data
{
int r;
char n[50];
char s[50];
};
int main()
{
struct data d; //HERE WE DEFINE THE VARIABLE FOR STRUCTURE//
struct data *dt; //HERE WE DEFINE THE POINTER TO STRUCTURE//
printf(“Input Regno.:”);
scanf(“%d”,&d.r);
printf(“\nInput name = “);
scanf(“%s”,&d.n);
printf(“\nInput section no. = “);
scanf(“%s”,&d.s);
dt=&d; //HERE WE TAKE THE VARIABLE’S ADDRESS IN POINTER//
printf(“\n\nNAME= %s \tREG.NO.=%d \tSECTION= %s\n”,dt->n,dt->r,dt->s); //THIS IS HOW WE PRINT POINTER TO STRUCTURE.//
printf(“\n\nPROGRAMMING AT CODE STUDIO”);
getch();
}
A structure contains various data type and it can also be transfer to a function: to transfer a structure we have to initialize it globally that it can be accessed through all the functions.
the prototype would be “int pass(‘datatype’)”
no such header files are define in program for structure .
example-
#include<stdio.h>
#include<conio.h>
int pass(char*,int); //prototype//
struct student
{
char name[10];
int rollno;
};
int main()
{
struct student s;
printf(“Input roll no.: “);
scanf(“%d”,&s.rollno);
printf(“\nInput name: “);
scanf(“%s”,s.name);
pass(s.name,s.rollno); //passing to function//
getch();
}
int pass(char*f,int l)
{
printf(“\nROLL NO.: %d\nNAME: %s”,l,f);
printf(“\n\n PROGRAMMING @ CODE STUDIO”);
}
#include<stdio.h>
#include<conio.h>
struct bookup //Structure for bookup//
{
char name[10];
int page;
float price;
};
struct bookin //structure for bookin//
{
char au[10];
int puby;
};
struct book //the both of bookup and bookin is defined in 3rd structure//
{
struct bookup b1;
struct bookin b2;
};
int main()
{
struct book b;
printf(“\nENTER BOOK NAME:”);
gets(b.b1.name); //this is like opening gate, 🙂 first b structure then b1 structure then name variable.//
printf(“\nENTER PAGES:”);
scanf(“%d”,&b.b1.page);
printf(“\nINPUT PRICE:”);
scanf(“%f”,&b.b1.price);
printf(“\nAUTHOR:”)
scanf(“%s”,&b.b2.au);
printf(“\nPublication year:”);
scanf(“%d”,&b.b2.puby);
printf(“\nBOOK:%s\nPAGES:%d\nPRICE:%f\nAUTHOR:%s\nPUBLICATION YEAR:%d”,b.b1.name,b.b1.page,b.b1.price,b.b2.au,b.b2.puby);
printf(“\n\nProgramming @ code studio.”);
}
STRUCTURE—Structure is as much as array but it have collection of diffrent data type also.
The structure keyword is : “struct”
#include<stdio.h>
#include<conio.h>
struct book //STRUCT COOMMAND IS USE TO DEFINE A STRUCTURE//
{
char name[10]; //HERE WE DEFINE BOOK NAME//
int page;
float price;
};
int main()
{
struct book b; //IN MAIN FN THE STRUCT COMMAND DEFINED BY A VARIABLE, HERE WE TAKE IT ‘b’//
printf(“\nENTER BOOK NAME:”);
gets(b.name); //HERE WE INSTRUT VARIABLE AS b.name WHERE B IS STRUCT BOOK VARIABLE AND NAME IS VARIABLE IN STRUCTURE//
printf(“\nENTER PAGES:”);
scanf(“%d”,&b.page);
printf(“\nINPUT PRICE:”);
scanf(“%f”,&b.price);
printf(“\nBOOK:%s\tPAGES:%d\tPRICE:%f”,b.name,b.page,b.price);
printf(“\nPROGRAMMING @ CODE STUDIO”);
getch();
}
#include<conio.h>
#include<stdio.h>
int main()
{
int arr1[5],arr2[5],arr3[5],i; //No. of element is written in subscript//
for(i=0;i<5;i++)
{
printf(“\ninput arr1 @ pos.%d = “,i+1); //input loop//
scanf(“%d”,&arr1[i]);
}
for(i=0;i<5;i++)
{
printf(“\ninput arr2 @ pos.%d = “,i+1);
scanf(“%d”,&arr2[i]);
}
for(i=0;i<5;i++)
{
arr3[i]=arr2[i]+arr1[i]; //here we store sum of 1st and 2nd array into 3rd array//
printf(“\narr1[%d]=%d \tarr2[%d]=%d \tarr3[%d]=%d”,i+1,arr1[i],i+1,arr2[i],i+1,arr3[i]); //u know how to print it//
}
printf(“\nPROGRAMMING @ CODE STUDIO”);
getch();
}