Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
an array of strings in C
Name: geo Date: July 20, 2003 at 13:19:06 Pacific OS: xp pro CPU/Ram: p3
Comment:
How do you allocate more memory for a pointer in straight C? in C++ it would look like this:
char *string; string = new char[11]; string = "hello world";
What I need to do is create and array of strings to hold file names. I have mostly C++ experience. I don't think the 'new' keyword is allowed in C.
Name: Don Arnett Date: July 20, 2003 at 13:44:33 Pacific
Reply:
You use malloc and calloc. Besides taking different parameters, the main difference is that calloc clears out the allocated memory by filling it with zeros.
The program below allocates an array of 5 character pointers and then assigns strings to the pointers. Many times you'll use calloc/malloc to allocate the individual strings also.
#include <stdio.h> #include <stdlib.h>
int main(void) { char **myFilenames; int filenameCount = 5;
Summary: Hi Guys, Can someone give me a simple example of how to read a file of userids and passwords such as a file called passwords containing: a001mm password1 cd98fk outwilldo lmn99p abc123456 into an arr...
Summary: im at a bit of a loss here. I never had to work with strings, so forgive me if it is trivial: i want to have an array of strings in C++, for example: string array[10]; array[0] = "I dont"; array[1] =...