I have the following code:
#include <string.h>
int main(void) {
char *buffer = NULL, **words = NULL, *aPtr = NULL, *sPtr;
int count = 0;
...
|
How would one implement a dynamic associative array that could take any number of mixed indices (integers, strings, or both)?
I aim to simulate structures by providing, for example, people[3].location as syntactical ... |
Gurus,
I have a Java background and need your help.
I have to write a function in c which will return a dynamic array of strings. Here are my requirements:
|
I am having issues with filling an array of strings that was created dynamically. The array basically contains two strings and I would like to print them both with their lengths. ... |
If I have the number of items in a var called "totalstrings" and a var called "string size" that is the string size of each item, how do I dynamically allocate ... |
I have char * lines[1000] string that can hold 1000 characters. How to create 100 arrays of that string. I get error with this code down.
char * lines[1000];
lines = (lines*)malloc(100 * ...
|
I'm trying to build a dynamically grown array of strings. Neither the number of strings nor the length of each string is known at compile time. Here's the code I came ... |
|
Ok so I've got the program running as I wanted, except it automatically allocates 16 bytes for each string even if the length is less than that. so for example turkey still gets allocated 16 instead of just 7 bytes. It does however expand correctly for longer strings. Richard starts at address 00331A18 Gilmore starts at address 00331A28 Paul starts at ... |
huohaod...@gmail.com wrote: [..] I tried char * mFileList[] = new char[index]; but got a syntax error. > char **mFileList = new char*[size]; > But let me reiterate, do NOT presume managing dynamic memory is easy or recommended. Try to stick to standard containers before you learn enough. Do > std::vector It's basically all you need, trust me. > V -- ... |
Hi, [color=blue] >From searching through the FAQ and the web, this seems to be a widely[/color] discussed topic, but I have not come up with a way that quite meets my needs. I have a sequence of files that contain tab/space separated data, with anywhere between 10 and 300 columns. Out of this data, I need only seven columns, but these ... |
Hi I want to scanf a number from the input and create a string array with that amount of strings. each string has 4 characters. i.e if the number is 3 I want to create an array that has enough space for 3 strings. Also how do i access each string? thank you very much in advance. |
You need to do more unit tests, in general. Unit tests (testing one function -- or unit -- at a time) make it clear what works and what does not. Then you can ask people for help on what does not work. By supplying my own is_delimiter function, I was able to get this result, with this test: Code: #include ... |
Hello, I have this program where I'm creating a list of strings and the list can expand to create more strings. The reason is because users can add words during runtime, and so it needs to be expandable. The size of the word is guaranteed to be less than 100, so I've allocated memory to be a little above 100 for ... |
#include #include #include int main(void) { char *options[] = {"Option 1", "Option 2", "Option 3"}; char **myStringArray; int i, numOps; numOps = sizeof(options) / sizeof(char *); myStringArray = malloc(numOps * sizeof(char *)); for (i = 0; i < numOps; i++) { myStringArray[i] = malloc(strlen(options[i]) * sizeof(char)); strcpy(myStringArray[i], options[i]); } for (i = 0; i < numOps; i++) { ... |
|
O.K. I did what you said and it fixed it, sort of. I added another parser and it stopped working. Below is the code. Code: char **add_string( char **list, char *add, int size ) { char **newList; int count; newList = (char **) malloc( sizeof( char* ) * ( size + 1 ) ); if( size > 0 ) for( count ... |
|
Hey all, Any ideas on how to concatenate strings that are refered to by an array of pointers to pointers? This is what I have at the moment: Code: #include #include #include #define MAX_NO_STR 10 #define MAX_LGT_STR 99 main(int argc, char *argv[]) { char **strings; int elements, i; strings = malloc( MAX_NO_STR * sizeof(char *) ); if(strings == ... |
#include #include #include struct ffblk ffblk; char **files; void countMem_to_Alloc(){ int done,counter=0,i; done = findfirst(fname,&ffblk,0); while(!done){ done = findnext(&ffblk); counter++; } files = malloc(counter * sizeof(char)); for(i=0;i |
Hello, I have this program where I'm creating a list of strings and the list can expand to create more strings. The reason is because users can add words during runtime, and so it needs to be expandable. The size of the word is guaranteed to be less than 100, so I've allocated memory to be a little above 100 for ... |
Hello all once again, and once again I'm trying to complete a project for school. We were never instructed to learn pointers, however, I'm having troubles seeing how they are not going to be needed for a requirement in the project. We are suppose to keep a database of customer names and at the end of the day total up each ... |
//char or char*?? charArray = (char) calloc(numNames, numChar);//creates 2D array if(charArray == NULL) { printf("Program error."); exit(0); } //get each name c = 0; for(i = 0; i < numNames; i++) { printf("\nEnter name %i: ", &i); for()//until final character is reached { *charArray = fgetc(stdin);//get char from keyboard c++; } if(i < numNames - 1)//if not on last name charArray ... |
|