Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include "helpers2.h"
  2. #include "hw2_p1.h"
  3. int contains(const char* str, const char c) {
  4. if (str == NULL || c == '\0'){
  5. return -1;
  6. }
  7. char* strPtr = str;
  8. int chCounter = 0;
  9. while (*strPtr != '\0'){
  10. if (*strPtr == c){
  11. chCounter++;
  12. }
  13. strPtr++;
  14. }
  15. return chCounter;
  16. }
  17.  
  18. char* prefix(const char* str, const char* tokens) {
  19. if (str == NULL || tokens == NULL){
  20. return NULL;
  21. }
  22. char* strPtr = str;
  23. char* tokPtr = tokens;
  24. while (*strPtr != '\0'){
  25. int retFlag = 1;
  26. while (*tokPtr != '\0'){
  27. if (*tokPtr == *strPtr){
  28. retFlag = 0;
  29. }
  30. tokPtr++;
  31. }
  32. if (retFlag){
  33. return strPtr;
  34. }else{
  35. strPtr++;
  36. tokPtr = tokens;
  37. }
  38. }
  39. }
  40.  
  41. int ics53atoi(const char *str) {
  42. char* strPtr = str;
  43. int place = 1;
  44. //we want to start at the end of the string
  45. if (*str == '-'){
  46. place = -1;
  47. strPtr++;
  48. }else if (*str == "\0"){
  49. errno = INTERR;
  50. return 0;
  51. }
  52. int out = 0;
  53. while( *strPtr != '\0'){
  54. int c = (int) ((*strPtr)-'0');
  55. //printf("%d\n", c);
  56. if ( c<0 || c > 9){
  57. errno = INTERR;
  58. //printf("RETURNING ZERO\n");
  59. return 0;
  60. }else{
  61. out *= 10;
  62. out += place * c;
  63. place *= 10;
  64. }
  65.  
  66. strPtr++;
  67. place=place*10;
  68. }
  69. return out;
  70.  
  71. }
  72.  
  73. float ics53atof(const char *str) {
  74. float x = 1.1;
  75. return x;
  76. /*
  77. char* strPtr = str;
  78. int place = 1;
  79. float fplace = 1/10;
  80. //we want to start at the end of the string
  81. if (*str == '-'){
  82. place = -1;
  83. strPtr++;
  84. }else if (*str == "\0"){
  85. errno = INTERR;
  86. return 0;
  87. }
  88. float out = 0;
  89. int isDec = 0;
  90. while( *strPtr != '\0'){
  91. int c = (int) ((*strPtr)-'0');
  92. //printf("%d\n", c);
  93. if ((c<0 || c > 9){
  94. if (c==-2 && isDec == 0){
  95. isDec = 1;
  96. }else{
  97. errno = INTERR;
  98. return 0;
  99. }
  100. }else if (isDec){
  101. out += (float)(fplace * c);
  102. fplace = fplace/10;
  103. }
  104. else{
  105. out *= 10;
  106. out += (float)(place * c);
  107. place *= 10;
  108. }
  109. strPtr++;
  110. }
  111. return out;*/
  112. }
  113.  
  114. char** getSubstrings(char *str, int *size) {
  115. }
  116.  
  117. void printSubstrings(const char** sstrs, const int size) {
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement