fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. char overeni[8];
  6. char znaminko[8];
  7. int count = 0;
  8. int n = 10;
  9. int* znamky = (int*) malloc (n * sizeof(int)); // I allocate memory here
  10. if (znamky == NULL)
  11. return EXIT_FAILURE;
  12. printf("Pocty bodu:\n");
  13. scanf("%c",&overeni[0]); // here I check if the first character is {; if not I exit program
  14. if (overeni[0]!='{')
  15. {
  16. printf("Nespravny vstup.\n");
  17. return EXIT_FAILURE;
  18. }
  19. while (scanf("%d",&znamky[count])!=EOF) //here I continue loading numbers, and char fight
  20. { //if the character after number is "," i load another
  21. if (scanf("%c",&znaminko[0])==1) //number, if it is "}"I exit the while cycle
  22. { // else I exit the program
  23. if (znaminko[0]==',') // if equals ","
  24. {
  25. printf("sdf\n");
  26. count++;
  27. if (count==n) // if I run out of memory I allocate more
  28. {
  29. n = n*2;
  30. znamky = (int*) realloc (znamky, n * sizeof(int) + 4);
  31. }
  32. continue;
  33. }
  34. if (znaminko[0]=='}') // if equals "}"
  35. {
  36. count++;
  37. printf("utikam\n");
  38. break;
  39. }
  40. }
  41. else
  42. {
  43. printf("Nespravny vstup\n");
  44. return EXIT_FAILURE;
  45. }
  46. }
  47.  
  48. printf("%d ",count); //here I just print length of my array
  49. //printArray(znamky,count);
  50.  
  51. free(znamky);
  52. return 0;
  53.  
  54. }
  55.  
Success #stdin #stdout 0.01s 5368KB
stdin
{2
stdout
Pocty bodu:
0