A MFC coder want to learn some basic about charecter array intialisation and deletion of element.Take following examples campare with MFC (there is CString so no need of memory allocation or de allocation but same needed in c.)
(dont have std::string interface :-()
To construct string we us following code in MFC.
constructString = "";
constructString = "ABC";
constructString = constructString + "PQR";
constructString = constructString + "LMN";
whatever size of string we have this will work.
for C i used following code
#define DEFAULT_ARRAY_SIZE 20000
char* constructString = new char[DEFAULT_ARRAY_SIZE];
1)Code will work fine till my char* constructString size is less than 20000 but when it exceed i dont have solution,how to resize my array so it will take more charecters.
2)I intialize char* constructString with 20000 but when my string is very small of size 10 then my remaining 18990 charecters are wasted or not i dont know,will this effect my executable perfomance.If yes then how to delete my remaining dummy charecters.
To read content from file we use following code in MFC.
Whitever size of File it will work fine.
For C i use following code
#define MAX_FILE_SIZE 65534
const char* list[MAX_FILE_SIZE];
int __index = 0;
while(fgetws (CurrentString , 1000 , ptr_file) != NULL)
errorDes = new char;
wcstombs(errorDes, CurrentString, 1000);
list[__index] = errorDes;
1)Same as above if my one line charecters exceed 1000 then more than 1000 charecters are not consider and vise versa.
2)If my file size exceed 65534 then char* list array will not fill properly and vise versa.
Please provide me any link,block of code,suggestion that help me to solve all problem in pure c.