Write
on the Data File
#include
#include
struct student
{
int roll;
char name[12];
int percent;
}
s1 = {
10, "SMJC", 80 };
int main()
{
FILE *fp;
struct student s2;
fp = fopen("ip.txt",
"w");
fwrite(&s1, sizeof(s1), 1,
fp);
fclose(fp);
fp = fopen("ip.txt",
"r");
fread(&s2, sizeof(s2), 1,
fp);
fclose(fp);
printf("\nRoll : %d",
s2.roll);
printf("\nName : %s",
s2.name);
printf("\nPercent :
%d", s2.percent);
return (0);
}
Output
Roll : 10
Name : SMJC
Percent : 80
C Program to Display same Source Code as Output
#include
#include
int main()
{
FILE *fp;
char ch;
fp = fopen(__FILE__,
"r");
do
{
ch = getc(fp);
putchar(ch);
}
while
(ch != EOF);
fclose(fp);
return 0;
}
Output
#include
#include
int main()
{
FILE *fp;
char ch;
fp = fopen(__FILE__,
"r");
do {
ch =
getc(fp);
putchar(ch);
} while (ch != EOF);
fclose(fp);
return 0;
}
C program to convert the file contents in Upper-case & Write Contents in a output file
#include
#include
void
main()
{
FILE*fp1,*fp2;
char a;
clrscr();
fp1=fopen("test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
a=toupper(a);
fputc(a,fp2);
}
while(a!=EOF);
fcloseall();
getch();
}
Drawing Line in Graphics Mode Using Graphics Function
#include
#include
#include
int main(void)
{
int gdriver = DETECT, gmode;
int x1 = 200, y1 = 200;
int x2 = 300, y2 = 300;
initgraph(&gdriver,
&gmode, "c:\\tc\\bgi");
line(x1, y1, x2, y2);
closegraph();
}
C Program to draw Inductive Coil using Graphical Function
#include
#include
#include
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm,
"c:\\tc\\bgi");
line(100, 200, 150, 200);
arc(200, 200, 0, 180, 50);
arc(260, 200, 0, 180, 50);
arc(230, 200, 180, 360, 20);
arc(320, 200, 0, 180, 50);
arc(290, 200, 180, 360, 20);
arc(380, 200, 0, 180, 50);
arc(350, 200, 180, 360, 20);
line(430, 200, 470, 200);
getch();
closegraph();
}
C Program to Draw Resistance using Graphics Function
#include
#include
#include
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm,
"c:\\tc\\bgi");
line(90, 100, 100, 100);
line(100, 100, 110, 120);
line(110, 120, 120, 100);
line(120, 100, 130, 120);
line(130, 120, 140, 100);
line(140, 100, 150, 120);
line(150, 120, 160, 100);
line(160, 100, 170, 100);
outtextxy(100, 130,
"Resisitor");
getch();
closegraph();
}
C Program to Draw PNP Transistor using Graphics Function
#include
#include
#include
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm,
"c:\\tc\\bgi");
line(100, 100, 100, 200);
line(70, 150, 100, 150);
line(100, 125, 150, 90);
line(100, 175, 150, 210);
line(100, 175, 110, 200);
line(100, 175, 125, 175);
outtextxy(200, 150, "PNP
Transistor");
getch();
closegraph();
}
No comments:
Post a Comment