James2007

Hi my name is James Grimshaw and I am doing project in GMIT, Castlebar, Ireland. I really need some help with this; I canĄŻt figure it out myself! I am doing a C++ project using Visual Studio 2005.

I am using 64 bit unsigned integers, and itĄŻs the first time I have ever use such big numbers. From what I can work out, they seem to be working. But I donĄŻt know how to print them to screen or a file. When I try it counts up to a certain number and stops, it wonĄŻt go beyond the limit of a double.

 

Here is my code I am using:

 

#include <stdio.h>

#include <math.h>

 

void main()

{

 

      int a,b,d,e,f;

      unsigned long long c, power=1;

      int Numbers[255000];

      int stop;

      int Kounter=64;

 

      FILE *fptr;

 

      for(a=0; a<255000; a++){

            Numbers[ a]=0;

      }

     

      if((fptr=fopen("Input.dat","r"))==NULL){

            printf("File Doesn't exist! Please create 'Input.dat' and enter numbers!");

      }

      a=0;

      while( !feof (fptr)){

            fscanf(fptr,"%c",&Numbers[ a]);

            if(Numbers[ a] == 49){

                  Numbers[ a]=1;

            }else{

                  Numbers[ a]=0;

            }

            a+=1;

      }

      fclose(fptr);

      stop =a-1;

 

 

 

      if((fptr=fopen("Kounter-report.txt","w+"))==NULL){

            printf("File Doesn't exist! Please create 'Kounter-report.txt' and enter numbers!");

      }

      a=0;

      do{

            b=0;

            f=a;

            for(e=f; e<(f+Kounter); e++){

                  fprintf(fptr,"%d",Numbers[ e]);

            }

            fprintf(fptr,"\n");

            do{

                  b+=1;

                  if ( Numbers[ a] == 1 ){

                        for (d=1; d<=b; d++){

                              power *= 2;

                        }

                        power = power/2;

                        c+=power;

                        fprintf(fptr,"\t%d",c);

                  }

                  a+=1;

                  power=1;

            }while ( b < Kounter );

            fprintf(fptr,"\n\t\t\t\t\t\t\t\t\t\t\t %ld \n",c);

            c=0;

      }while (a<255000);

}

 

What I am doing: I read in the binary from a file, find the power (by the way couldnĄŻt get the power function to work right either! Again because of the double limit!) of the 1ĄŻs. Add the values up and then print them to a file. I know itĄŻs the Ą°%dĄ± which is wrong, but I canĄŻt find the answer I need. I tried a whole bunch of things. But none of them seem to do the trick.

 

IĄŻve been searching on the Internet for days now.

I wonder if you might help a frustrated C++ programmer

James

 




Re: Visual C++ General Large (int64) interger Variables

Alex Farber

To print long long with printf, use ll prefix:

%lld

See MSDN topic "Size and Distance Specification ".

http://msdn2.microsoft.com/en-us/library/tcxf1dw6(VS.80).aspx