Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

#include<stdio.

h>
#include<conio.h>
void main()
{
char state[40],buf[35];
int i=0,j,p=0,f=0,s=0,fi=0;
clrscr();
printf("\n \t INPUT BUFFERING WITH SENTINALS \n");
scanf("%s",state);
buf[16]='$';
buf[32]='#';
if(state[i]!='\0')
{

bh:

printf("\nFilling the 1st block...\n");


for(i=0;i<15;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
p++;
}
else
{
buf[i]=state[p];
i++;
buf[i]='~';
//printf("GOTO");
goto h;
}
} //end of i
printf("\nReading from buffer\n");

h:

if(i<17)
{
i=0;
for(i=0;i<=16;i++)
{
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=0;
if(buf[i]=='~')
fi=1;
if(f!=1 && s!=1 && fi!=1)
{
printf("\nNOT THE END: %c",buf[i]);
getch();
}
else
{
if(f!=1)
printf("\n 1.Not the end of first half ");
else
{
f=0;
printf("\nEnd of first half\nLOADING THE BUFFER....... ");
for(i=17;i<32;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
//printf("\nbuf[%d]=%c",i,buf[i]);
//getch();
p++;
}
else
{
//buf[i]=state[p];
//i++;
buf[i]='~';
//printf("\nbuf[%d]=%c",i,buf[i]);
getch();
goto bhav;
}
}//for loop end
goto bhav;
}//end of else
if(s!=1)
{
printf(" 2.Not the End of second half ");
}
if(fi!=1)
{
printf(" 3.Not End of file\n");
}
else
{
printf("\n End of file\n");
getch();
goto end;
}
}
}//end of j loop
}//end of checking string

bhav:

//printf("%d",i);
if(i>15 && i<=32)
{
//printf("buf[%d]=%c",i,buf[i]);
for(i=17;i<=32;i++)
{
//printf("buf[%d]=%c",i,buf[i]);
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=1;
if(buf[i]=='~')
fi=1;
if(f!=1 && s!=1 && fi!=1)
{
printf("\nNOT THE END: %c",buf[i]);
getch();
}
else
{
printf("\nEND IS FOUND");
if(f!=1)
printf("\n 1.Not end of first half ");
if(s!=1)
{
printf(" 2.Not end of second half ");
}
else
{
s=0;
printf("\n\n\tEnd of Second half");
goto bh;
}
if(fi!=1)
printf(" 3.Not end of file\n");
else
{
printf(" \n\tEnd of file");
getch();
goto end;
}
}
}
}
}
else
{
printf("\n END");
}
end:
getch();
}

#include<stdio.h>
#include<conio.h>
void main()
{
char state[40],buf[35];
int i=0,j,p=0,f=0,s=0,fi=0;
clrscr();
printf("\n \t INPUT BUFFERING WITH SENTINALS \n");
scanf("%s",state);
buf[16]='$';
buf[32]='#';
if(state[i]!='\0')
{

bh:
printf("\nFilling the 1st block...\n");
for(i=0;i<15;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
p++;
}
else
{
buf[i]=state[p];
i++;
buf[i]='~';
//printf("GOTO");
goto h;
}
} //end of i
printf("\nReading from buffer\n");

h:

if(i<17)
{
i=0;
for(i=0;i<=16;i++)
{
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=0;
if(buf[i]=='~')
fi=1;
if(f!=1 && s!=1 && fi!=1)
{
printf("\nNOT THE END: %c",buf[i]);
getch();
}
else
{
if(f!=1)
printf("\n 1.Not the end of first half ");
else
{
f=0;
printf("\nEnd of first half\nLOADING THE BUFFER....... ");
for(i=17;i<32;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
//printf("\nbuf[%d]=%c",i,buf[i]);
//getch();
p++;
}
else
{
//buf[i]=state[p];
//i++;
buf[i]='~';
//printf("\nbuf[%d]=%c",i,buf[i]);
getch();
goto bhav;
}
}//for loop end
goto bhav;
}//end of else
if(s!=1)
{
printf(" 2.Not the End of second half ");
}
if(fi!=1)
{
printf(" 3.Not End of file\n");
}
else
{
printf("\n End of file\n");
getch();
goto end;
}
}
}//end of j loop
}//end of checking string

bhav:

//printf("%d",i);
if(i>15 && i<=32)
{
//printf("buf[%d]=%c",i,buf[i]);
for(i=17;i<=32;i++)
{
//printf("buf[%d]=%c",i,buf[i]);
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=1;
if(buf[i]=='~')
fi=1;
if(f!=1 && s!=1 && fi!=1)
{
printf("\nNOT THE END: %c",buf[i]);
getch();
}
else
{
printf("\nEND IS FOUND");
if(f!=1)
printf("\n 1.Not end of first half ");
if(s!=1)
{
printf(" 2.Not end of second half ");
}
else
{
s=0;
printf("\n\n\tEnd of Second half");
goto bh;
}
if(fi!=1)
printf(" 3.Not end of file\n");
else
{
printf(" \n\tEnd of file");
getch();
goto end;
}
}
}
}
}
else
{
printf("\n END");
}
end:
getch();
}

#include<stdio.h>
#include<conio.h>
void main()
{
char state[40],buf[35];
int i=0,j,p=0,f=0,s=0,fi=0;
clrscr();
printf("\n \t INPUT BUFFERING WITHOUT SENTINALS \n");
scanf("%s",state);
buf[16]='$';
buf[32]='#';
if(state[i]!='\0')
{

bh:

printf("\nFilling the 1st block...\n");


for(i=0;i<15;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
p++;
}
else
{
buf[i]=state[p];
i++;
buf[i]='~';
printf("GOTO");
goto h;
}
} //end of i
printf("\nReading from buffer\n");

h:

if(i<17)
{
i=0;
for(i=0;i<=16;i++)
{
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=0;
if(buf[i]=='~')
fi=1;
if(f!=1)
printf("\n 1.Not the end of first half ");
else
{
f=0;
printf("\nEnd of first half\nLOADING THE BUFFER....... ");
for(i=17;i<32;i++)
{
if(state[p]!=';')
{
buf[i]=state[p];
//printf("\nbuf[%d]=%c",i,buf[i]);
//getch();
p++;
}
else
{
//buf[i]=state[p];
//i++;
buf[i]='~';
//printf("\nbuf[%d]=%c",i,buf[i]);
getch();
goto bhav;
}
}//for loop end
goto bhav;
}//end of else
if(s!=1)
{
printf(" 2.Not the End of second half ");
}
if(fi!=1)
{
printf(" 3.Not End of file\n");
}
else
{
printf("\n End of file\n");
getch();
goto end;
}
if(f!=1 && s!=1 && fi!=1)
{
printf("\n %c",buf[i]);
getch();
}
}//end of j loop
}//end of checking string

bhav:

//printf("%d",i);
if(i>15 && i<=32)
{
//printf("buf[%d]=%c",i,buf[i]);
for(i=17;i<=32;i++)
{
//printf("buf[%d]=%c",i,buf[i]);
if(buf[i]=='$')
f=1;
if(buf[i]=='#')
s=1;
if(buf[i]=='~')
fi=1;
if(f!=1)
printf("\n 1.Not end of first half ");
if(s!=1)
{
printf(" 2.Not end of second half ");
}
else
{
s=0;
printf("\n\n\tEnd of Second half");
goto bh;
}
if(fi!=1)
printf(" 3.Not end of file\n");
else
{
printf(" \n\tEnd of file");
getch();
goto end;
}
if(f!=1 && s!=1 && fi!=1)
{
printf("\n %c",buf[i]);
getch();
}
}
}
}
else
{
printf("\n END");
}
end:
getch();
}

You might also like