Newsgroup: it.comp.lang.c++
Titolo: Programma in cui printf non stampa

Ho compilato il programma riportato qui sotto con g++ -g -o Base64
Base64.cpp.
La compilazione è andata a buon fine, ma l'esecuzione ha un problema
che si presenta solo sul mio computer e cioè la printf nel "main" non
stampa.
Il sistema operativo è Linux 2.4.3 dstribuito da Mandrake (8.0). La
libreria è libstdc++-libc6.2-2.a.3
Grazie
// Translates a binary stream into a string encoded according to the
//base 64 representation
// and viceversa.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream.h>
class binaryStream
{
private:
  unsigned char* binStream;
  unsigned long binLength; // ricordarsi di trattare il caso di
overflow
  unsigned int pointer;
  // Reads n bits from the stream and updates the starting read point.
  // If there are no more things to be read, returns -1
  // int readNextBits(int bitsToRead, int bitsActuallyRead);
 
public:
  // Costructor 
  binaryStream(unsigned char* stream, unsigned long len)
  {
    binStream = stream;
    binLength = len;
    pointer = 0;
  }
  int readNextBits(int, int& );
  unsigned char* decode(unsigned char*, int&);
  //  unsigned char* encode();
};
int binaryStream::readNextBits(int bitsToRead, int& bitsActuallyRead)
{
  unsigned int newPointer;
  bitsActuallyRead = bitsToRead;
  // Out of range error
  if (bitsToRead > 24 || bitsToRead < 1) 
    {
      cerr << "Error in read\n";
      exit(1);
    }
  // No more things to be read
  if (pointer == binLength) 
    {
      bitsActuallyRead = 0;
      return -1; 
    }
  // Too many bits to be read 
  if (pointer + bitsToRead > binLength) 
    {
      bitsToRead = binLength - pointer;
      bitsActuallyRead = bitsToRead;
    }
  newPointer = pointer + bitsToRead;
 
  unsigned int value = 0;
  int j = 16;
  for (int i = pointer/8; i < newPointer/8 ; i++)
    {
      value += binStream[i] << j;
      j -= 8;
      //      cout << value << " ";
    }
  pointer = newPointer;
  return value;
}
unsigned char* binaryStream::decode(unsigned char* binary, int&
bitsNum)
{
  const int newDim = 1 + 3*((int) ceil((double)bitsNum / 24.0));
  unsigned char* decodedString = new unsigned char[newDim];
  int slice;
  int bitsRead;
  int eqNum = 0;
  char valTrans[64] = 
  { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I' ,'J',
    'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S' ,'T',
    'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
    'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
    'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
    'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
    '8', '9', '+', '/'};
  int j = 0;
 
  while( (slice = readNextBits(24, bitsRead)) != -1 )
    {
      if (bitsRead != 24)
	{
	  // Determines the number of = to attach
	  // at the end of decoded string
	  eqNum = (int) floor((24.0 - (double)bitsRead)/6.0);
	}
 
      unsigned int mask = 0xfc0000 ;
 
      // Fills the string translating the binary one
      for (int i = 0; i < 4 - eqNum; i++)
	{
	  decodedString[j++] = valTrans[(slice & mask) >> 6*(3-i)];
	  mask = mask >> 6;
	}
 
    } // end while
 
  // Completes with equal signs
  for (int i = 0; i < eqNum; i++)
    {
      decodedString[j++] = '=';
    }
 
 
  decodedString[j] = 0;
 
  return decodedString;
}
void main()
{
  int a = 56;
  puts("abcdse");
  binaryStream A( (unsigned char*)"abcdefg", 56l);
  unsigned char* n = A.decode((unsigned char*)"abcdefg", a);
  printf("buzzicus");
  puts("abcdse");
  printf("%d ",(char*)n);
}

 supermegagalactik cut
Prova a mettere lo \n in fondo alle tue printf.
Maurus