Mar 10, 2010

Synchronous TDM and Asynchronous TDM

// This is  Synchronous TDM developed using C
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k=0,l,maxlength=0,length[3],flag1=0,flag2=0,flag3=0;
char usr1[10],usr2[10],usr3[10],newusr1[10],newusr2[10],newusr3[10],b[100];
printf("enter data for user 1\n");
gets(usr1);
printf("enter data for user 2\n");
gets(usr2);
printf("enter data for user 3\n");
gets(usr3);
length[0]=strlen(usr1);
length[1]=strlen(usr2);
length[2]=strlen(usr3);
for(j=0;j<3;j++)
{
if(maxlength<length[j])
maxlength=length[j];
}
for(i=0;i<maxlength;i++)
{
if(usr1[i]!=NULL && flag1==0)
b[k++]=usr1[i];
else
{
b[k++]='$';
flag1=1;
}
if(usr2[i]!=NULL && flag2==0)
b[k++]=usr2[i];
else
{
b[k++]='$';
flag2=1;
}
if(usr3[i]!=NULL && flag3==0)
b[k++]=usr3[i];
else
{
b[k++]='$';
flag3=1;
}
}
b[k]=NULL;
k=0;
for(i=1;i<=maxlength;i++)
{
printf("\nframe %d is ",i);
for(j=0;j<3;j++)
printf("%c",b[k++]);
}
strcpy(newusr1,usr3);
strcpy(newusr2,usr1);
strcpy(newusr3,usr2);
printf("\nTransferring Data To Respective Users...\n\n");
printf("user1 gets %s \n",newusr1);
printf("user2 gets %s \n",newusr2);
printf("user3 gets %s \n",newusr3);
return 0;


}


//This is  Asynchronous TDM developed using C

#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
int i,j,k=0,l,frame,maxlength=0,length_t=0,length[3],flag1=0,flag2=0,flag3=0;
char usr1[10],usr2[10],usr3[10],newusr1[10],newusr2[10],newusr3[10],b[100];
printf("enter data for user 1\n");
gets(usr1);
printf("enter data for user 2\n");
gets(usr2);
printf("enter data for user 3\n");
gets(usr3);
length[0]=strlen(usr1);
length[1]=strlen(usr2);
length[2]=strlen(usr3);
for(j=0;j<3;j++)
{
length_t+=length[j];
if(maxlength<length[j])
maxlength=length[j];
}

if(length_t%2==0)
frame=length_t/2;
else
frame=(length_t/2)+1;
printf("\ntotal frames are %d\n",frame);

for(i=0;i<maxlength;i++)
{
if(isalpha(usr1[i]))
b[k++]=usr1[i];
if(isalpha(usr2[i]))
b[k++]=usr2[i];
if(isalpha(usr3[i]))
b[k++]=usr3[i];
}
b[k]=NULL;
k=0;
for(i=1;i<=frame;i++)
{
printf("\nframe %d is ",i);
for(j=0;j<2;j++)
printf("%c",b[k++]);
}
k=0;
for(i=0;i<frame;i++)
{
if(i<strlen(usr1))
newusr2[i]=b[k++];
if(i<strlen(usr2))
newusr3[i]=b[k++];
if(i<strlen(usr3))
newusr1[i]=b[k++];
}
newusr1[strlen(usr3)]=NULL;
newusr2[strlen(usr1)]=NULL;
newusr3[strlen(usr2)]=NULL;
printf("\nTransferring Data To Respective Users...\n\n");
printf("user1 gets %s \n",newusr1);
printf("user2 gets %s \n",newusr2);
printf("user3 gets %s \n",newusr3);
return 0;
}

No comments:

Post a Comment