Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *pszBUF;
- char *pszPos;
- int accum(int n, const char *psz);
- ///////////////////////////////////////////////////////////////////////////////
- int main() //
- {
- int nArr[17];
- accum(1, "void");
- nArr[1] = accum(0, "SONY");
- nArr[2] = accum(0, " Pictures");
- nArr[3] = accum(0, " TDK");
- printf("%s\n", pszBUF);
- printf("nArr[1] = %d\n", nArr[1]);
- printf("nArr[2] = %d\n", nArr[2]);
- printf("nArr[3] = %d\n", nArr[3]);
- // printf("%s\n", p[2]);
- printf("%s\n", pszBUF + nArr[3]);
- }
- // n = 1; âûäåëèì 1000 ñèìâîëîâ
- // n = 2; ðàñøèðèì äî 2000 áàéò
- ////////////////////////////////////////////////////////////////////////////////
- int accum(int n, const char *psz)
- {
- switch(n)
- {
- case 1: pszBUF = (char*)malloc ( 1000);
- pszPos = pszBUF;
- *pszBUF = 0; return 0;
- case 2: pszBUF = (char*)realloc(pszBUF, 2000); return 0;
- }
- int nLen = strlen(psz);
- strcat(pszPos, psz);
- int nOffset = pszPos - pszBUF;
- pszPos += nLen;
- return nOffset;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement