get paid to paste

codigo

/* verbinario.c */

#include <stdio.h>

#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))


void byteToVetor (unsigned char b, char* vetor);


int main (int argc, char* argv[])
{
   FILE *arq;
   char vetor[7];
   char buf[3];


   if (argc!=2)
   {
      printf ("Parametro incorreto.\n");
      printf ("Informe apenas o nome do arquivo\n");
      return 1;
   }

   if (!(arq=fopen(argv[1],"r")))
   {
      printf ("Nao foi possivel abrir o arquivo!\n");
      return 1;
   }


   while (f=fread(buf,1,1,arq))
   {

      byteToVetor (buf[0],buf);
      printf ("%s ",buf);
      printf ("\n");
 
   }

   printf ("\n");
   close (arq);
}


void byteToVetor (unsigned char b, char* vetor)
{
int i;
i = 0;
while (i < 8)
if CHECK_BIT(b, i) { vetor[i] = 1;} else {vetor[i] = 0;}
i++;
 
}

Pasted: Oct 26, 2011, 12:47:09 pm
Views: 2