09-14-2007
Use an array of 80 pointers to character. As you encounter each string to be stored in this array, find the length of that string and then call malloc to allocate space for the string. This way you only allocate as much space as you need and you do not establish an arbitrary limit on the length of the string.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a perl script with an array of clients.
@arr = ("The ABC Corp", "AA Corp.", "BB Corp");
If I run
@a = sort (@arr);
I will get
@a = ("AA Corp", "BB Corp", "The ABC Corp");
but I want
@a = ("AA Corp, "The ABC Corp", "BB Corp");
How do I sort array without changing... (2 Replies)
Discussion started by: photon
2 Replies
2. Programming
I've been struggling with this for quite some time. I decided I should get some help with this. Nothing is working. I'm getting a segmentation fault or out of bounds error when I try to load the entries in the for loop.I'm really frustrated. :mad: Compiling isn't the problem. It's crapping out on... (5 Replies)
Discussion started by: sepoto
5 Replies
3. Shell Programming and Scripting
I am wanting to take a list of strings and loop through a list of textfiles to find matches. Preferably with awk and parsing the search strings into an array.
// Search_strings.txt
tag
string
dummy
stuff
things
// List of files to search in
textfile1.txt
textfile2.txt
The... (6 Replies)
Discussion started by: sdf
6 Replies
4. Shell Programming and Scripting
I have a file search_strings.txt filled with search strings which have a blank in between and look like this:
S. g. Erh.
o. J.
v. d. Chijs
g. Ehr.I would like to search the strings in the second given Textfile.txt and it shall return the column number.
Can anybody help with the correct... (3 Replies)
Discussion started by: sdf
3 Replies
5. Programming
I am trying to get userinput from stdin and store the lines in an array.
If i do this:
using a char **list to store strings
allocate memory to it
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv)
{
char *prog = argv;
char **linelist;
int... (5 Replies)
Discussion started by: tornow
5 Replies
6. UNIX for Dummies Questions & Answers
i have a list of apps that i need to forcequit and, from time to time, that list changes. perfect excuse to manage a single array! however, my strings with spaces aren't passing as i'd like them to. here's the simple script:
#!/bin/sh
#-----Array
apps=( firefox-bin firefox... (6 Replies)
Discussion started by: hungryd
6 Replies
7. Shell Programming and Scripting
Hi,
Can anybody help me in finding the difference between two array elements with the help of code pls.
purge=("Purge Concurrent Request and/or Manager Data" "Purge Signon Audit data" "Purge Obsolete Workflow Runtime Data" "Purge Logs and Closed System Alerts")
purge_1=("Purge Obsolete... (3 Replies)
Discussion started by: Y.balakrishna
3 Replies
8. Programming
I put together a C function to add strings to a dynamic array of strings (mostly for educational purpose to explain pointers to my kid). It works, but sometimes one or two strings in the array becomes corrupted. Running example on 64 bit Ubuntu, gcc ver. 4.8.4
Hope my code is self-explanatory:
... (2 Replies)
Discussion started by: migurus
2 Replies
9. Shell Programming and Scripting
i need to add 2 string variables into a positioning array , repeatedly - in loop.
First string in $2, second to $3 then up to the desired count incrementing the "position".
Using set -- alone does not increment the count so I end up with 2 variables in the array.
How do I increment the... (7 Replies)
Discussion started by: annacreek
7 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
I have a file with around 1000 rows and one of the fields is an account number. I have been provided with a few account numbers, when any of the account number appears in a row then the row has to be deleted.
Can we place the account numbers in an array and use awk or sed for this task?... (3 Replies)
Discussion started by: mrcool4
3 Replies
LEARN ABOUT SUSE
tcl_newbytearrayobj
Tcl_ByteArrayObj(3) Tcl Library Procedures Tcl_ByteArrayObj(3)
__________________________________________________________________________________________________________________________________________________
NAME
Tcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj, Tcl_SetByteArrayLength - manipulate Tcl objects as a arrays of bytes
SYNOPSIS
#include <tcl.h>
Tcl_Obj *
Tcl_NewByteArrayObj(bytes, length)
void
Tcl_SetByteArrayObj(objPtr, bytes, length)
unsigned char *
Tcl_GetByteArrayFromObj(objPtr, lengthPtr)
unsigned char *
Tcl_SetByteArrayLength(objPtr, length)
ARGUMENTS
const unsigned char *bytes (in) The array of bytes used to initialize or set a byte-array object.
int length (in) The length of the array of bytes. It must be >= 0.
Tcl_Obj *objPtr (in/out) For Tcl_SetByteArrayObj, this points to the object to be converted to byte-array type. For
Tcl_GetByteArrayFromObj and Tcl_SetByteArrayLength, this points to the object from which to
get the byte-array value; if objPtr does not already point to a byte-array object, it will be
converted to one.
int *lengthPtr (out) If non-NULL, filled with the length of the array of bytes in the object.
_________________________________________________________________
DESCRIPTION
These procedures are used to create, modify, and read Tcl byte-array objects from C code. Byte-array objects are typically used to hold
the results of binary IO operations or data structures created with the binary command. In Tcl, an array of bytes is not equivalent to a
string. Conceptually, a string is an array of Unicode characters, while a byte-array is an array of 8-bit quantities with no implicit
meaning. Accessor functions are provided to get the string representation of a byte-array or to convert an arbitrary object to a byte-
array. Obtaining the string representation of a byte-array object (by calling Tcl_GetStringFromObj) produces a properly formed UTF-8
sequence with a one-to-one mapping between the bytes in the internal representation and the UTF-8 characters in the string representation.
Tcl_NewByteArrayObj and Tcl_SetByteArrayObj will create a new object of byte-array type or modify an existing object to have a byte-array
type. Both of these procedures set the object's type to be byte-array and set the object's internal representation to a copy of the array
of bytes given by bytes. Tcl_NewByteArrayObj returns a pointer to a newly allocated object with a reference count of zero. Tcl_SetByteAr-
rayObj invalidates any old string representation and, if the object is not already a byte-array object, frees any old internal representa-
tion.
Tcl_GetByteArrayFromObj converts a Tcl object to byte-array type and returns a pointer to the object's new internal representation as an
array of bytes. The length of this array is stored in lengthPtr if lengthPtr is non-NULL. The storage for the array of bytes is owned by
the object and should not be freed. The contents of the array may be modified by the caller only if the object is not shared and the call-
er invalidates the string representation.
Tcl_SetByteArrayLength converts the Tcl object to byte-array type and changes the length of the object's internal representation as an
array of bytes. If length is greater than the space currently allocated for the array, the array is reallocated to the new length; the
newly allocated bytes at the end of the array have arbitrary values. If length is less than the space currently allocated for the array,
the length of array is reduced to the new length. The return value is a pointer to the object's new array of bytes.
SEE ALSO
Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount
KEYWORDS
object, byte array, utf, unicode, internationalization
Tcl 8.1 Tcl_ByteArrayObj(3)