i have a small app to be compiled into a .lib file. it accepts a char * array
and the array count, outputs a '-' and then reads in a line and (supposed) to
parse it into the recieved char * arrays. i know im doing something wrong
with writing to the memory locations but i cant figure it out. heres the code:
Code:const int MAX_CHARS = 255; extern "C" MYAPI void getArgs(int argC, char * argV[]) { char holder[MAX_CHARS]; cout << "-"; cin.getline(holder, MAX_CHARS-1); strcat(holder, "\0"); int index=0; //array index nBytes=1; //#of bytes to copy pos=0; //placeholder in holder string int chr; for (int i = 0; i < (int)strlen(holder)+1; i++) { chr = (int)*(char*)&holder[i]; if (chr == 32 || chr == 0) //space or end string { if (index < argC) { //copy nBytes-1, (nbytes is the string + the //space char or end string memcpy(&argV[index], &holder[pos], nBytes-1); pos = i+1; //skip whitespace in $ holder index++; } else break; nBytes = 1; } else nBytes++; } } ############# //in the host application that calls that const int MAX_ARGS = 4; char * args[MAX_ARGS]; getArgs(2, args); //is it ok to use a number smaller than the //actual # char* arrays?




Reply With Quote