I wrote this code in interest of learning stdio.h somewhat fleuently... but it decided to be bugged on me... what may be the bug??

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
int main()
{
FILE * bin;
char buffer[100];
bool test;
int a;
bin = fopen ("bin1.raw", "wb");
std::cin.getline(buffer, 100);
for (int a = 0; a < 100; a++)
{
putchar(buffer[a]);
}

for (int i = 0; i < 100; i++)
{
if (!test)
{
if (!buffer)
{
bool test = 1;
a = i;
i = 0;
}
}
else
{
if (i < a)
{
putchar(buffer[i]);
putc(buffer[i], bin);
}
}
}
fclose(bin);

system("PAUSE");
return 0;
}


i was just trying to output only the amount of text used... there are easier ways of going about this problem... but one thing led to another and this is what i got. im not that interested in the "working project" but the "why it wont work"