why cant i get this int64 working?
i compile with g++ -x c++ -o program source.c
it keeps starting over with -2147483648 above 2147483647 ….
#include <stdint.h>
#include <inttypes.h>
#ifdef __cplusplus
#include <cstdio>
#include <cstdlib>
#include <cstring>
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
int main(int argc, char* argv[])
{
int64_t i;
for(i = 0; i < argc; ++i)
printf("argv[%d]: %s\n", i, argv[i]);
char string [512];
int64_t a1 = atoi((const char*) gets(string));
int64_t limit = a1 + 99999999999
while(a1 <= limit)
{
char command[10000];
sprintf(command, "%d", a1);
FILE* pFile = fopen ("myfile.txt","wa");
fprintf (pFile, "%s\n", command);
fclose (pFile);
a1= a1 + 4321;
}
return EXIT_SUCCESS;
}
c
I think you should replace
with
Using the wrong format specifier is undefined behaviour. AFAIK, using
%das the format specifier in gcc forces only 32 bits to be printed out – thus resulting in what looks like overflows in your output file.