Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "helpers2.h"
- #include "hw2_p1.h"
- int contains(const char* str, const char c) {
- if (str == NULL || c == '\0'){
- return -1;
- }
- char* strPtr = str;
- int chCounter = 0;
- while (*strPtr != '\0'){
- if (*strPtr == c){
- chCounter++;
- }
- strPtr++;
- }
- return chCounter;
- }
- char* prefix(const char* str, const char* tokens) {
- if (str == NULL || tokens == NULL){
- return NULL;
- }
- char* strPtr = str;
- char* tokPtr = tokens;
- while (*strPtr != '\0'){
- int retFlag = 1;
- while (*tokPtr != '\0'){
- if (*tokPtr == *strPtr){
- retFlag = 0;
- }
- tokPtr++;
- }
- if (retFlag){
- return strPtr;
- }else{
- strPtr++;
- tokPtr = tokens;
- }
- }
- }
- int ics53atoi(const char *str) {
- char* strPtr = str;
- int place = 1;
- //we want to start at the end of the string
- if (*str == '-'){
- place = -1;
- strPtr++;
- }else if (*str == "\0"){
- errno = INTERR;
- return 0;
- }
- int out = 0;
- while( *strPtr != '\0'){
- int c = (int) ((*strPtr)-'0');
- //printf("%d\n", c);
- if ( c<0 || c > 9){
- errno = INTERR;
- //printf("RETURNING ZERO\n");
- return 0;
- }else{
- out *= 10;
- out += place * c;
- place *= 10;
- }
- strPtr++;
- place=place*10;
- }
- return out;
- }
- float ics53atof(const char *str) {
- float x = 1.1;
- return x;
- /*
- char* strPtr = str;
- int place = 1;
- float fplace = 1/10;
- //we want to start at the end of the string
- if (*str == '-'){
- place = -1;
- strPtr++;
- }else if (*str == "\0"){
- errno = INTERR;
- return 0;
- }
- float out = 0;
- int isDec = 0;
- while( *strPtr != '\0'){
- int c = (int) ((*strPtr)-'0');
- //printf("%d\n", c);
- if ((c<0 || c > 9){
- if (c==-2 && isDec == 0){
- isDec = 1;
- }else{
- errno = INTERR;
- return 0;
- }
- }else if (isDec){
- out += (float)(fplace * c);
- fplace = fplace/10;
- }
- else{
- out *= 10;
- out += (float)(place * c);
- place *= 10;
- }
- strPtr++;
- }
- return out;*/
- }
- char** getSubstrings(char *str, int *size) {
- }
- void printSubstrings(const char** sstrs, const int size) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement