EmbLogic's Blog

C assignment

IThis following c program working fine but i am unable to understand the flow of program. Please explain.

#include
char input[] = “SSSWILTECH1\1\11W\WALLMP1″;

int main()
{
int i,c;
for(i=2;(c= input[i])!=”;i++)
{
// printf(“==c:%d..%ci\n”,c,c);
switch(c)
{
case ‘a’: putchar(‘i’); continue;
case ’1′: break;
case 1:while((c=input[++i])!=’\1′ && c!=”);
case 9: putchar(‘S’);
case ‘E’:
case ‘L’:continue;
defualt: putchar(c);continue;

}
putchar(”);
}
// printf(“\n”);
return 0;
}

One Response to C assignment

  1. kamran says:

    it is very simple break it down as follows:
    for loop start with i = 2 and
    input[i] contains SSSWILTECH1\1\11W\WALLMP1

    so input[2] = S (since array start from 0)

    This input(2) i.e. S is pass into he switch case. Since no case is defined for S it will be passed to default .

    The default says putchar(c) i.e is S
    and second line say continue.
    So hole process will go on again.
    Now you can try it for rest of the values of i.
    You will get the final output.

    Note: Here is a catch \ is a escape sequence so the compiler will ignore the next char after \.

Leave a Reply to kamran Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>