You're getting somewhere, definitely. I would just make sure that you compile in such a way that catches mistakes like confusing = for == and vice versa.

Code:
C:\Users\jk\Desktop>gcc -Wall -std=c99 -c foobar.c
foobar.c: In function 'main':
foobar.c:31:13: warning: statement with no effect [-Wunused-value]
             flag == 0;
             ^
foobar.c:37:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
         if (flag = 1)
         ^
foobar.c:39:13: warning: statement with no effect [-Wunused-value]
             c == i + count;
             ^
foobar.c:42:19: warning: statement with no effect [-Wunused-value]
                   TextAfter[i] == TextAfter[c];
                   ^
foobar.c:42:44: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
                   TextAfter[i] == TextAfter[c];
                                            ^
It looks like you have the meaning of these operators backwards.