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.
Storing numbers in a character array
Started by KeilanS, Nov 24 2008 09:39 AM
20 replies to this topic
#1
Posted 24 November 2008 - 09:39 AM
|
|
|
#2
Posted 24 November 2008 - 10:09 AM
Quote
I'm writing a program that needs to take in a 2000 x 2000 multidimensional array.
Quote
But when I output it gives me all single characters, or it will give me the ASCII character. Not the number.
#3
Posted 24 November 2008 - 12:08 PM
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.
And I will try the cast thing. Thanks.
#4
Posted 24 November 2008 - 03:01 PM
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.
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.
#5
Posted 24 November 2008 - 03:37 PM
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.
char myData[2000][2000]; //requires typecasting __int8 myOtherData[2000][2000]; //no typecasting
__int8 is signed by default.
#6
Posted 24 November 2008 - 05:58 PM
My computer prof requires us to compile and run our programs under Fedora Linux. Thanks though, I'll keep that in mind.
#7
Posted 24 November 2008 - 07:32 PM
From my base/types.h file, these are guaranteed to be the proper size by C/C++
typedef unsigned int u32int; typedef int s32int; typedef unsigned short u16int; typedef short s16int; typedef unsigned char u8int; typedef char s8int;
#8
Posted 24 November 2008 - 07:46 PM
C99 specifies minimum widths. These could be off.
#9
Posted 24 November 2008 - 07:49 PM
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
Format: intN_t and uintN_t ; where N is the width
#10
Posted 24 November 2008 - 09:24 PM
Sorry guys, these last 3 messages are over my head. :P
Beyond what I've learnt in the class so far.
Beyond what I've learnt in the class so far.
#11
Posted 24 November 2008 - 09:44 PM
Here's a question for you ^^ Is this in C or C++.
#12
Posted 25 November 2008 - 05:10 AM
For clarification, my post is based on C99.


Sign In
Create Account


Back to top









