Data Communication network programs (DCN)
Data Communication network(DCN) program to implement the peer to peer (chatting) application.
Write a program to implement the peer to peer (chatting) application.
Program Code:
#include<stdio .h="">
#include<conio .h="">
void main()
{
FILE *fs,*ft;
char ch,str[40];
char s[80];
clrscr();
fs=fopen("sample.txt","w+");
if(fs==NULL)
{
puts("\nCannot open source file");
exit();
}
ft=fopen("sample2.txt","w");
if(ft==NULL)
{
puts("\nCannot open target file");
fclose(fs);
exit();
}
printf("\n Enter the text to be sent...\n");
while(strlen(gets(str))>0)
{
fputs(str,fs);
fputs("\n",fs);
}
rewind(fs);
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
fputc(ch,ft);
}
fclose(fs);
fclose(ft);
printf("\n After reading contents from receiver:\n");
ft=fopen("sample2.txt","r");
if(ft==NULL)
{
puts("\n cannot open");
exit();
}
Output:
Enter the text to be sent...
The Final submission of DCN
(Practicals)
After reading contents from receiver:
The Final submission of DCN
(Practicals)</conio></stdio>