If I have a structure as follows;
typedef struct {
double x;
double y;
int size;
char text[256];
} text;
I have allocated a space of 256 bytes for some text entered. If the text is
less than 256 bytes, what happens to the rest of them.
I am interested as I want to append other objects after the text in memory,
and if the user only enters a few bytes, I only want to use that amount of
data (rounded to the next word);
if C automatically either writes the remaining bytes to a specific value, or
currupts them, I will have to do this another way.
--
David Buck
2D CAD for RISC OS at www.risccad.freeuk.com 3 1565
David Buck wrote: If I have a structure as follows;
typedef struct { double x; double y; int size; char text[256]; } text;
I have allocated a space of 256 bytes for some text entered. If the text is less than 256 bytes, what happens to the rest of them.
Nothing. You asked for 256 characters; that's what you got. If you don't
care to use them, well, that's fine.
I am interested as I want to append other objects after the text in memory, and if the user only enters a few bytes, I only want to use that amount of data (rounded to the next word);
C doesn't let you randomly append objects to the end of data structures.
if C automatically either writes the remaining bytes to a specific value,
No (not unless you allocate a static text).
or currupts them,
No (but it won't stop /you/ corrupting them).
I will have to do this another way.
Yes, if you only want to use "enough" space: point into larger character
buffers or use mallocated space.
--
Chris "hey, dude, where's my train?" Dollin
Chris Dollin wrote: David Buck wrote:
If I have a structure as follows;
typedef struct { double x; double y; int size; char text[256]; } text;
I have allocated a space of 256 bytes for some text entered. If the text is less than 256 bytes, what happens to the rest of them.
Nothing. You asked for 256 characters; that's what you got. If you don't care to use them, well, that's fine.
I am interested as I want to append other objects after the text in memory, and if the user only enters a few bytes, I only want to use that amount of data (rounded to the next word);
C doesn't let you randomly append objects to the end of data structures.
I didn't say random, nor to the end of data structures, all I said was after
this object in memory. It would be another structure, but I will point it to
the next word aligned address after the text - hence the question. if C automatically either writes the remaining bytes to a specific value,
No (not unless you allocate a static text).
or currupts them,
No (but it won't stop /you/ corrupting them).
I will have to do this another way.
Yes, if you only want to use "enough" space: point into larger character buffers or use mallocated space.
Sounds like it will work OK.
Thanks for the info - much appreciated.
--
David Buck
2D CAD for RISC OS at www.risccad.freeuk.com
"David Buck" <da********@freeuk.com> wrote in message
news:dq**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... Sounds like it will work OK.
Thanks for the info - much appreciated.
-- David Buck 2D CAD for RISC OS at www.risccad.freeuk.com
You might be interested in article 2.6 in the FAQ http://c-faq.com/struct/structhack.html
--
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
I'm bad at regular expressions. Is this how I would look for any set
of characters that go more than 60 characters without a white space?
..{60}
Also, does this match a block of PHP in an...
|
by: lixiaoyao |
last post by:
hi all
I use matrix & vector function to allocate the space myself in c,
typedef struct matrix_array newdata;
struct matrix_array{
float **sy,*sxx;
};
newdata ndata;//new data struct...
|
by: Otto Meijer |
last post by:
Hi everyone,
for one of my projects I need to figure out the size of the
swap file(s) of a certain system. The problem is I need to do this
on a host of platforms like: HP_UX, Solaris, Linux,...
|
by: Eirik |
last post by:
Look at this code:
#include <stdio.h>
int main(void) {
char name;
printf("What is your name?\n");
fgets(name, sizeof(name), stdin);
printf("Your name is %s.\n", name);
|
by: Gattaca |
last post by:
I would like to create a matrix of integers by allocating memory
dynamically (malloc or calloc) because i and j are defined during
execution of the program.
I have got not problem to do this in...
| |
by: james |
last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits
the "," and then copies the results into a listbox. The data also...
|
by: Jukka K. Korpela |
last post by:
I recently noticed, once again, how the common implementation of italics can
really disturb. I'm referring to the common phenomenon that there is by
default too little spacing after italics text,...
|
by: kvnsmnsn |
last post by:
I've written the following Javascript file that includes an input text
field and an output text field, the latter of which is initialized to
zero. Each time the user enters a number in the input...
|
by: arunajob |
last post by:
Hi all,
If I have a piece of code something like this
void main(void)
{
char * p1="abcdefghijklmn";
.............................................
}
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |
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...
| |