Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- char sz[199] = "This is for our of a recursive, we could get an infinite loop for n because of the way the function. hjkhkjhjkh jkhjkhkj";
- char *pszArr[11];
- int nLen = 0;
- int search_3(char *psz);
- int foo(char *p);
- /////////////////////////////////////////////////////////////
- int main()
- {
- int i = 0;
- while(1)
- {
- if(sz[++i] == '.')
- {
- nLen = i;
- break;
- }
- }
- printf("nLen = %d\n", nLen);
- printf("Find = %d\n", i = search_3(sz));
- // for(int j = 1; j <= i; j++)
- for(int x = 1; x <= i; x++)
- {
- if(foo(pszArr[x]))
- {
- printf("address = %d, %.*s\n", pszArr[x], 3, pszArr[x]);
- }
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////
- int foo(char *p)
- {
- // printf("%.*s\n", 3, p);
- //for(int i = 0)
- char cz[9] = "0";
- strncpy(cz, p, 3);
- cz[3] = 0;
- //printf("%s\n", cz);
- if(strstr(cz, "way")!=0) { printf("***\n"); return 0; }
- return 1;
- }
- //////////////////////////////////////////////////////////////
- int search_3(char *psz)
- {
- int nIndx = 1,
- nCounter = 0;
- for(int i = 0; i < nLen; i += 1)
- {
- if(psz[i] == ' ')
- {
- pszArr[nIndx] = &psz[i] + 1;
- if(psz[i+4] == ' ')
- if(psz[i+1] != ' ')
- if(psz[i+2] != ' ')
- if(psz[i+3] != ' ')
- {
- nCounter ++;
- nIndx ++;
- i+=3;
- }
- }
- }
- return nCounter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement