473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Array of Strings??

Hey everyone, I have created a struct called employee, as follows:

struct employee {
int pid;
char name[3];
char job[40];
int hourlyRate;
struct employee *next;
}

Which will become a linked list (obviously!).. Now I want to add one more
field, a "appointment" field... Now the idea is that when a customer wants
to book the particular employee they put their name in the corresponding
array slot. ( eg. Ms. Saunders wants 10 am should be appointments [10] =
"Ms. Saunders" ) however I have no idea of how to create an array of
strings.. or even if it's possible.. Bit of a noob, i know! (But u gotta
start at some point!!)

Any other suggestions will be welcomed and the entired project can be sent
via e-mail upon request if you wish to have a closer look.. :)

Simon
Nov 14 '05 #1
4 35389
"Simon Mansfield" <gl************@ntlworld.com> wrote in message
news:rt**************@newsfe3-gui.ntli.net...
I have no idea of how to create an array of
strings.. or even if it's possible


An array of strings is created the same way an array of anything else is
created: you start with your BASE element and extend an array.

For example, a BASE element, and an array of 5 integers:

int ele;
int group[5];

Here ele is the name of a BASE, and group is the name of an array of
elements.

Character strings are no different. Your BASE element is declared as:
char *string;

karl m
Nov 14 '05 #2
Simon Mansfield wrote:
"Ms. Saunders" ) however I have no idea of how to create an array of
strings.. or even if it's possible.. Bit of a noob, i know! (But u gotta
start at some point!!)


I had this problem too.

an array of strings:

char **array;
int nstr; /* Number of strings */
int wstr; /* String width */

nstr = 8;
/* Allocate memory for the array of pointers
* (which point to the strings) */
array = (char **) calloc (nstr, sizeof (char *));

/* Memory is statically allocated for string */
array[0] = "text";

/* Memory is dynamically allocated for string */
wstr = 80;
array[2] = (char *) calloc (wstr, sizeof (char));

/* Reads a string from stdin */
fgetc (array[2], wstr, stdin);

Nov 14 '05 #3

"Simon Mansfield" <gl************@ntlworld.com> wrote in message
news:rt**************@newsfe3-gui.ntli.net...
Hey everyone, I have created a struct called employee, as follows:

struct employee {
int pid;
char name[3];
char job[40];
int hourlyRate;
struct employee *next;
}

Which will become a linked list (obviously!).. Now I want to add one more
field, a "appointment" field... Now the idea is that when a customer wants
to book the particular employee they put their name in the corresponding
array slot. ( eg. Ms. Saunders wants 10 am should be appointments [10] =
"Ms. Saunders" ) however I have no idea of how to create an array of
strings.. or even if it's possible.. Bit of a noob, i know! (But u gotta
start at some point!!)

Any other suggestions will be welcomed and the entired project can be sent
via e-mail upon request if you wish to have a closer look.. :)


How about

struct employee {
int pid;
char name[3];
char job[40];
int hourlyRate;

char appointment[12][40]; /*12 appointments with room for 39 characters
in each string*/

struct employee *next;
}
Nov 14 '05 #4
Thanks a lot everyone... I think i'm going to try to attempt something along
the lines of what code_wrong suggested, since it seems to be the simplest
solution and I am trying to keep things simple :)

Thanks all.. I'll let you know if I have any further problems.

Simon
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
2
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...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
11
by: Bob Rock | last post by:
Hello, I have an array of strings and need to find the matching one with the fastest possible code. I decided to order the array and then write a binary search algo. What I came up with is the...
3
by: Morten71 | last post by:
I have a strange problem. I have a local string() var I populate this way: clmns() As String = {"InvoiceNo", "InvoiceDate"} When I call: Array.IndexOf(clmns,"InvoiceDate") I get 0 (zero) as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.