Wednesday, March 5, 2014

Frame creation

Formation of frames

The following code creates frames of size "n". The frame starts with a symbol and ends with a symbol. These frames are useful for transmitting information. Simple implementation is shown below:

Suppose the input is "Abhishek Baddi" . Let's take the start symbol to be '$' and stop symbol to be '@'. The frames would be:

$Abhi@
$shek@
$ Bad@
$di  @
The code is shown below:
/*
 * ----------------------------------------------------------------------------
 * "THE BURGER-WARE LICENSE" (Revision 42):
 * <abybaddi009@gmail.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a burger in return. Abhishek Baddi
 * ----------------------------------------------------------------------------
 */
 
#include<stdio.h>
#include<string.h>

int main() {
    char a[20],STARTSYMBOL='$',STOPSYMBOL='@';
    int i,j,lenOfa;
    int FRAMESIZE=4;
    printf("Enter a string: ");
    gets(a);
    lenOfa=strlen(a);
    i=0;
    while(i<lenOfa) {
        printf("%c",STARTSYMBOL);
        for(j=0;j<FRAMESIZE;++j) {
            printf("%c",i<lenOfa?a[i]:' ');
            i++;
        }
        printf("%c\n",STOPSYMBOL);
    }
    return 0;
}

The output is shown below:

No comments:

Post a Comment