I have an int variable (always <100) that I want to convert to a two character string, e.g.
if myint = 1, mystr = "01"
if myint = 81, mystr = "81"
At the moment I can't figure out how to do this cleanly.
Then I wish to push a bunch of these strings into an array, for example:
typedef char LABEL[3];
LABEL mystrArray[100];
But having read a couple of tutorials I am still no clearer on the best way to do an "array of strings" in this situation, nor
how to do it.
Any help much appreciated!
cheers,
Ben
Jun 22 '06
14 1453
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.edu> wrote: Ben <be*********@sp am.me> writes:
I have an int variable (always <100) that I want to convert to a two character string, e.g.
if myint = 1, mystr = "01"
For a problem as simple as this, though, you can easily do it by hand, if you like: mystr[0] = myint / 10 + '0'; mystr[1] = myint % 10 + '0';
mystr[2] = 0;
double-quoted strings are null terminated...
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
"Ben" <be*********@sp am.me> wrote in message
news:12******** *****@corp.supe rnews.com...
[snip] This compiles and runs ok but doesn't work as required since each update to alabel, blabel etc changes those objects that all the pointers point to, so I am not storing new labels just overwriting the same ones (the print contents at 2) confirms that). Note I want the whole structure labelArray to be available globally which is another problem with the code above.
So I need to do something differently, perhaps the 2d array, but I couldn't get that to compile. At least the values at 1) are correct, just the structure is wrong.
What is the exact problem that you are trying to solve?
Dann Corbit wrote: What is the exact problem that you are trying to solve?
Well, I've now worked around the problem (still without knowing how to build an array of strings). But it was part of a sudoku
solver. I was incorporating someone else's program for solving exact cover problems and had to remap some data.
On 2006-06-24, Ben <be*********@sp am.me> wrote: Dann Corbit wrote: What is the exact problem that you are trying to solve?
Well, I've now worked around the problem (still without knowing how to build an array of strings). But it was part of a sudoku solver. I was incorporating someone else's program for solving exact cover problems and had to remap some data.
(Overly long lines corrected)
What exact problem involving the C language are you having, what
code are you having trouble with, what is it doing, and what
/should/ it be doing?
Since in C, strings are null-terminated arrays of char, an array
of strings could be implemented as an array of arrays of char.
char stringArr[5][10]; /* Allows 5 strings of max 9 length */
I'm not sure if the 5 and the 10 need to be switched for my
comment to be true.
--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head.
"Ben" <be*********@sp am.me> wrote Dann Corbit wrote: What is the exact problem that you are trying to solve?
Well, I've now worked around the problem (still without knowing how to build an array of strings). But it was part of a sudoku solver. I was incorporating someone else's program for solving exact cover problems > and had to remap some data.
Not all character data has to be in ASCIIZ strings.
Sudoku, in case anyone doesn't know consists of a 9x9 grid, containing
digits 1-9. No digit can be repeated in any line, column, or 3x3 box.
The obvious way to represent the board in C is
char sudoku[9][9].
Now say we want to print out the board to the user. The obvious way to do
that is
for(i=0;i<9;i++ )
{
for(ii=0;ii<9;i i++)
putc(sudoku[i][i]]);
putc('\n');
}
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ravi |
last post by:
Hi,
I have about 200GB of data that I need to go through and extract the
common first part of a line. Something like this.
>>>a = "abcdefghijklmnopqrstuvwxyz"
>>>b = "abcdefghijklmnopBHLHT"
>>>c = extract(a,b)
>>>print c
"abcdefghijklmnop"
|
by: Gordon Airport |
last post by:
Has anyone suggested introducing a mutable string type (yes, of course)
and distinguishing them from standard strings by the quote type - single
or double? As far as I know ' and " are currently interchangeable in all
circumstances (as long as they're paired) so there's no overloading to
muddy the language. Of course there could be some interesting problems
with current code that doesn't make a distinction, but it would be dead
easy to fix...
|
by: Paul Prescod |
last post by:
I skimmed the tutorial and something alarmed me.
"Strings are a powerful data type in Prothon. Unlike many languages,
they can be of unlimited size (constrained only by memory size) and can
hold any arbitrary data, even binary data such as photos and movies.They
are of course also good for their traditional role of storing and
manipulating text."
This view of strings is about a decade out of date with modern
programmimg practice. From...
|
by: John Bailo |
last post by:
The war of the OSes was won a long time ago.
Unix has always been, and will continue to be, the Server OS in the form
of Linux.
Microsoft struggled mightily to win that battle -- creating a poor man's
DBMS, a broken email server and various other /application/ servers to
try and crack the Internet and IS markets.
In the case where they didn't spend their own money to get companies to
|
by: agent349 |
last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1
== array2)). However, I've been trying to compare two arrays using
pointers with no success. Basically, I want to take three sets of
character strings from the user. Then I want to run through each
element and compare the two strings. If they match I print they
match... I'm having a bit of trouble with the actual loop through each
array using the pointers and comparing...
| |
by: Potiuper |
last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C?
Given: code is written in ANSI C; I know the exact nature of the strings to be read (the file will be written by only this program); file can be either in text or binary (preferably binary as the files may be read repeatedly); the amount and size of strings in the array won't be known until run time (in the example I have it in...
|
by: hstagni |
last post by:
Where can I find a library to created text-based windows applications?
Im looking for a library that can make windows and buttons inside
console.. Many old apps were make like this, i guess
____________________________________
| |
| ------------------ |
| | BUTTON | |
| ...
|
by: Krustov |
last post by:
$rambo="daffy duck";
$rambo="mad max";
$rambo="daffy duck";
$rambo="superman";
etc etc
How do i remove duplicate strings from a array ? .
('daffy duck' could appear more than twice in the array)
|
by: machineghost |
last post by:
First off, let me just say that as someone with no DBA training
whatsoever, any help I can get with this issue will be very, very much
appreciated.
My company recently migrated our database from DB2 v7 to DB2 v9. We
hired a consultant to help us, and things went pretty smoothly ... up
until a few weeks after, when a co-worker tried to insert JavaScript
in to our database. That's when we learned that v9, unlike v7, has a
problem with...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |