I'm writing a program that needs to take in a 2000 x 2000 multidimensional array.
All the entries in the array are numbers between -1 and 100.
So I use a nested loop to take all the numbers and store them in the array. But when I output it gives me all single characters, or it will give me the ASCII character. Not the number.
That's a lot of space. Do you have to have all of the numbers in memory at once?I'm writing a program that needs to take in a 2000 x 2000 multidimensional array.
I guess you're using an array of char to hold the numbers? char is treated specially on the assumption that you want a character and not a small integer, so you need to do some casting to int when printing.But when I output it gives me all single characters, or it will give me the ASCII character. Not the number.
I do have all the numbers in memory at once. I realize it's taking up about 4MB of memory.
And I will try the cast thing. Thanks.
Yep, that helped! I also found out another problem. The program was storing the -1 as 2 characters.
The first one was '-' and the second was '1'. So I fixed that by inputting into an int, then storing the int as a char.
A nonstandard way of fixing that would be to declare the array as an array of __int8. I'm pretty sure that's just a Microsoft extension.
__int8 is signed by default.Code:char myData[2000][2000]; //requires typecasting __int8 myOtherData[2000][2000]; //no typecasting
My computer prof requires us to compile and run our programs under Fedora Linux. Thanks though, I'll keep that in mind.
From my base/types.h file, these are guaranteed to be the proper size by C/C++
Code:typedef unsigned int u32int; typedef int s32int; typedef unsigned short u16int; typedef short s16int; typedef unsigned char u8int; typedef char s8int;
C99 specifies minimum widths. These could be off.
Check out 7.18.1.1 and 7.18.1.2 for information on the exact specifications. Although it is basically implementation defined, but required if the width exists.
Format: intN_t and uintN_t ; where N is the width
Sorry guys, these last 3 messages are over my head.
Beyond what I've learnt in the class so far.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks