Tuesday, 30 July 2013

To transfer a character from one computer to another.


To transfer a character from one computer to another.



Source Code at Transmitter side:


#include<iostream.h>
#include<dos.h>
#include<io.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
void main()
{
clrscr();
int choice;
cout<<"enter the choice\n";
cout<<"1: character transfer\n";
cout<<"2: string transfer\n";
cout<<"3: file transfer";
cin>>choice;*/
switch(choice)
{
case 1:
void c_transfer();
break;
case 2:
void s_transfer();
break;
case 3:
void f_transfer();
break;
default:
cout<<"Invalid choice";
}
void c_transfer()
{
char ch;
outport(0x3FB,0x8f);
outport(0x3f8,0x00);
outport(0x3f9,0x24);
outport(0x3f9,0x0f);
cout<<"the character recieved is";
cin>>ch;
outport(0x3fb,ch);
cout<<"data has been trasmitted";
getch();
}
oid s_transfer()
{
char s[10];
cout<<"enter the string to be transmitted";
for(i=0;i<10;i++)
{
cin<<s[i];
}
for(i=0;i<10;i++)
{
outport(0x3FB,0x8f);
outport(0x3f8,0x00);
outport(0x3f9,0x24);
outport(0x3f9,0x0f);
outport(0x3f8,s[i]);
}
cout<<"data has been trasmitted";
}
void f_transfer()
{
FILE *f1;
char ch;
f1=fopen("c:\test.txt","w");
while( (ch=getc(f1)) !=EOF)
{
ch=getc(f1);
cout<< ch;
outport(0x3f8,ch);
}
fclose(f1);
ch='0';
outport(0x3f8,ch);
cout<<"file is transmitted \n";
}
}


Source Code at Receiver side:


#include<iostream.h>
#include<dos.h>
#include<io.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
void main()
{
clrscr();
int choice;
cout<<"enter the choice\n";
cout<<"1: character transfer\n";
cout<<"2: string transfer\n";
cout<<"3: file transfer";
cin>>choice;
switch(choice)
{
case 1:
void c_transfer();
break;
case 2:
void s_transfer();
break;
case 3:
void f_transfer();
break;
default:
cout<<"Invalid choice";
}
void c_transfer()
{
char ch;
outport(0x3FB,0x8f);
outport(0x3f8,0x00);
outport(0x3f9,0x24);
outport(0x3f9,0x0f);
ch=inport(0x3f8);
cout<<"the character recieved is"<<ch;
getch();
}
void s_transfer()
{
char s[10];
for(i=0;i<10;i++)
{
outport(0x3FB,0x8f);
outport(0x3f8,0x00);
outport(0x3f9,0x24);
outport(0x3f9,0x0f);
s[i]=inport(0x3f8);
}
cout<<"the string recieved is"<<s;
}
void f_transfer()
{
FILE *f1;
char ch='1','0';
outport(0x3FB,0x8f);
outport(0x3f8,0x00);
outport(0x3f9,0x24);
outport(0x3f9,0x0f);
f1=fopen("c:\test.txt","w");
cout<<"recieving Data<<end;
while(c!='0')
{
ch=inport(0x3f8);
if(a==c)
{
break;
}
cout<<'l';
cout<<ch;
fclose(f1);
cout<<"Data received";
getch();
}


Compilation /Running and Debugging the Solution

• Go to Compile Menu and Press the Compile for the Compilation of the code.
• If Successful Compilation is done then Run the Code Using ctrl + F9 key.
Before Compilation, following steps are to be followed:
• Step 1: Create a folder in either E or F drive with your Id Number or Name Followed by
RollNo.
• Step 2: Start the TC (Turbo C) from Desktop Icon or Go To Directory D:/TC/BIN/ and
run tc.exe . An Editor will be start.
• Step 3: Click on File Menu --> New. New (.cpp) file will be created. Again Click on File
-> Save. A dialog box will open. Write the path to your directory e.g. E:\CCN_Program
\FileName.CPP and Press OK. Now your cpp program will be saved in your directory.
• Step 4: Go To Option->Directories Check That Include Directory is set As D:\TC\Include
and Library Directory is set To D:\TC\LIB

No comments:

Post a Comment