array of strings


 
Thread Tools Search this Thread
Top Forums Programming array of strings
# 1  
Old 09-12-2007
array of strings

Hi
I need a better idea to implementing following in my code.

I need to store 80 long strings that will be used to display one by one in my GUI application. now i am storing those 80 long string in following two dimentational array.

uchar vpn_alm_long_str[MAX_ALARM][1024]={ }

each index will be an string index .
all strings would be defined static and this variable would be a global one .
so the issues that i can forsee

some issue with where this will be stored like in data segment (but don't know exactly the issue?/)
does not look good to store such big data structure in memnory when they are not going to be used always.
Insetad , if we can write all these strings in a file in a special format , and on run time we extract these string from that file , that sounds a good idea .
at least that file would be stored on disk not in the memory , and that would be brought in the memory only when it will be required to read and even that would be the only a string not the complete file ..

pls any other idea??

dav
# 2  
Old 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete rows based on array of strings

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

2. Shell Programming and Scripting

Putting strings into positioning array in loop

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

3. Programming

Memory corruption in dynamic array of strings

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

4. Shell Programming and Scripting

Finding difference in between two array's of strings

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

5. UNIX for Dummies Questions & Answers

Problems passing strings within an array

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

6. Programming

C; storing strings in an array

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

7. Shell Programming and Scripting

Search strings from array in second file

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

8. Shell Programming and Scripting

awk search strings from array in textfile

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

9. Programming

Multidimensional array of strings with vector.

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

10. Shell Programming and Scripting

sort() array of strings in perl

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
Login or Register to Ask a Question