Q:

Looping over bits in C

I'm a C newbie, I want to store input bits to an output array according to the below procedure.
input           MSB                  LSB MSB                  LSB MSB              
[169,48,0] =     1  0  1  0  1  0  0  1   0  0  1  1  0  0  0  0   0  0  0  0  0  0  0  0 

The program should loop over the input data to find- in which byte the start index is present and extract the bits from start index till the end index and store it in the output[ ]. As an example my start index is 4 and it is present in input[0], my end index is 13. So I need to extract from bit position 4 to 13 and place it in output[ ].   
What I meant when I said bit position 4 to 13 is that - I need bits[4 - 7] = {0 1 0 0 1} from input[0] and bits[8 - 13] = {1 1 0 0 0 0} from input[1]
expected
output
[9, 48,0] =     0  0  0  0  1  0  0  1   0  0  1  1  0  0  0  0   0  0  0  0  0  0  0  0

I tried to program in C but unfortunately I wasn't successful, the looping over bits is through LSB to MSB. I need to loop over 1st byte and continue to the next byte and repeat till the byte index where the end position is present.
#include<stdio.h>
int main()
{
    unsigned char input[3] = {169,48,0};
    unsigned char output[3]= {0};
    int i, start = 4, end = 13;
    for(i=0; i<3; i++)
    {
        output[i] = (input[i] >> (start)) & ((1u << (end)) -1u);
        printf("%u\n",output[i]);
    }
    return 0;
}

The program loops over all 3 input bytes and stores from bit index 4 to end index of that particular byte i.e 7. 
output
[10, 3, 0] =     0  0  0  0  1  0  1  0   0  0  0  0  0  0  1  1   0  0  0  0  0  0  0  0 

I want to check whether my start index is present in input[0] or input[1] or . . . input[n], copy and store from start index to end index(that may be present in any byte position) as per the expected output shown in the beginning. 
I would be greatfull if you could correct the program logic as I'm new to C.

A:

Welcome to the forum.

I would be greatfull if you could correct the program logic as I'm new to C.

Here's a tentative effort. Your main logic is in the following line:
output[i] = (input[i] >> (start)) & ((1u << (end)) -1u);

This is easier to analyze by simplifying it to the following (and using a temporary unsigned char variable tmp):
tmp = input[i] >> start; // (1)
tmp &= (1u << end) - 1u; // (2)
// etc.

It is not clear to me precisely what you are trying to do here. I believe what you should be trying to do is extracting 8-start bits from input[i] and start bits from input[i+1] and placing a logical OR of these values (appropriately shifted) in a temporary variable. If this is so, then my suggestions are the following.
In the first line (1) you are shifting the wrong direction: it should be
tmp = input[i] << start;

The next line (2) is not accomplishing anything. (You are effectively AND'ing with zero.) Also, you should be using | rather than &, and the second operand should be a selection of bits (appropriately shifted) from the next byte.
tmp |= input[i+1] >> (8-start);

This, then, is the extraction stage. Next would be the insertion stage in the output stream. There are more nuances not discussed above but that gives the general idea. (See below for an implementation which handles more details.)

I want to check whether my start index is present in input[0] or input[1] or . . . input[n]

For this use
int idx = start / 8; // byte index
int offset = start % 8; // bit position within byte

P.S. Your original question indicated that the offset of the extracted bits could be different in the output stream than in the input stream. Your edits hide that fact, but the implementation below allows for this possibility (a 'transposition').
Possible implementation
void transpose_bits(unsigned char *a, unsigned char *b, int start, int end, int dest, size_t array_len) {
    unsigned char tmp = '\0', tmp2 = '\0';
    int offset = 0, idx = 0, len = 0, next_bits = 0;
    char bitmask = 0x80;

    len = end - start;
    while (len > 0) {
        // Single pass - transpose up to 8 bits ...
        tmp = tmp2 = '\0';

        // Determine the byte index and offset in the input byte array.
        idx = start / 8;
        offset = start % 8;
        tmp = a[idx] << offset;
        next_bits = offset + len - 8;
        if (next_bits < 0) {
            // Don't even need all of current byte  => remove trailing bits ...
            tmp &= bitmask >> (len - 1);
        } else if (next_bits > 0) {
            // Need to include part of next byte ...
            tmp2 = a[idx + 1] & (bitmask >> (next_bits - 1));
            tmp |= tmp2 >> (8 - offset);
        }

        // Determine byte index and offset in output byte array
        idx = dest / 8;
        offset = dest % 8;
        b[idx] |= tmp >> offset;
        b[idx + 1] |= tmp << (8 - offset);
        // Update start position and length for next pass ...
        if (len > 8) {
            len -= 8;
            dest += 8;
            start += 8;
        } else
            len -= len;
    }
}

Sample usage:
// Extract bits: 'start' and 'dest' are the same.
transpose_bits(input, output, 4, 13, 4, 3); // Assume arrays are of length '3'

// Transpose bits: 'start' and 'dest' not the same.
transpose_bits(input, output, 4, 13, 10, 3);

Notes:

The char[] arrays must be unsigned (as you have correctly chosen) - as the right shift operator works differently with signed values.
You should check the bounds of the arrays (comparing idx against array_len); I have skipped that here for brevity
Each iteration in the while() loop of the transpose_bits() function can handle up to 8 bits. By using multiple passes, it can handle an arbitrary number.

