fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX_WORDS 1000
  6. #define MAX_LEN 10000
  7.  
  8. int FindCharInString(char * src, int pos, char letter)
  9. {
  10. unsigned int i = pos;
  11. while(i < strlen(src))
  12. {
  13. if(src[i] == letter)
  14. return i;
  15. i = i + 1;
  16. }
  17. return -1;
  18. }
  19.  
  20. int main(int argc, char ** argv)
  21. {
  22. char pBufferIn[MAX_LEN];
  23. unsigned long ulLenBufferIn = 0;
  24. unsigned long ulCurrentPosInBuffer = 0;
  25. unsigned long ulFindedChar = 0;
  26. char ** pszBufferOut = (char**)(malloc(MAX_WORDS * sizeof(char*)));
  27. int iWords = 0;
  28. int i = 0;
  29.  
  30. puts("Ciag znakow > \n");
  31. scanf("%s", pBufferIn);
  32.  
  33. ulLenBufferIn = strlen(pBufferIn);
  34.  
  35. while(1)
  36. {
  37. ulFindedChar = FindCharInString(pBufferIn, ulCurrentPosInBuffer, '+');
  38. if(ulFindedChar == -1)
  39. {
  40. pszBufferOut[iWords] = (char*)(malloc( ulLenBufferIn - ulCurrentPosInBuffer + 1));
  41. memcpy(pszBufferOut[iWords], (char*)(pBufferIn+ulCurrentPosInBuffer), ulLenBufferIn - ulCurrentPosInBuffer);
  42. pszBufferOut[iWords][ulLenBufferIn - ulCurrentPosInBuffer] = '\0';
  43. iWords = iWords + 1;
  44. break;
  45. }
  46.  
  47. pszBufferOut[iWords] = (char*)(malloc(ulFindedChar - ulCurrentPosInBuffer + 1));
  48. memcpy(pszBufferOut[iWords], (char*)(pBufferIn+ulCurrentPosInBuffer), ulFindedChar - ulCurrentPosInBuffer);
  49. pszBufferOut[iWords][ulFindedChar - ulCurrentPosInBuffer] = '\0';
  50.  
  51. ulCurrentPosInBuffer = ulFindedChar + 1;
  52. iWords = iWords + 1;
  53. }
  54.  
  55. while(i < iWords)
  56. {
  57. printf("[%i] = %s\n", i, pszBufferOut[i]);
  58.  
  59. i = i + 1;
  60. }
  61.  
  62. i = 0;
  63. while(i < iWords)
  64. {
  65. free(pszBufferOut[i]);
  66. i = i + 1;
  67. }
  68.  
  69. free(pszBufferOut);
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0s 2432KB
stdin
a+ab+abc+ab+a+fsdf+hgfghvb+234dsfa+dASDGDSGSDFSDGDF+fasdfdasfhdfgjvbxcvz+dfassdtrehdfhdb+fsdfhjgfncvxczdsf+fdsfhfdhs+1243435346+fdsfsacxz+41326t45dsfsdrf3fe+dfvasf+4+fsdas34rf3
stdout
Ciag znakow > 

[0] = a
[1] = ab
[2] = abc
[3] = ab
[4] = a
[5] = fsdf
[6] = hgfghvb
[7] = 234dsfa
[8] = dASDGDSGSDFSDGDF
[9] = fasdfdasfhdfgjvbxcvz
[10] = dfassdtrehdfhdb
[11] = fsdfhjgfncvxczdsf
[12] = fdsfhfdhs
[13] = 1243435346
[14] = fdsfsacxz
[15] = 41326t45dsfsdrf3fe
[16] = dfvasf
[17] = 4
[18] = fsdas34rf3