Skip to content

Commit

Permalink
functional!
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 4, 2023
1 parent 7bb88e9 commit 8ea4843
Show file tree
Hide file tree
Showing 7 changed files with 1,268 additions and 1,216 deletions.
74 changes: 37 additions & 37 deletions helpers/flipbip_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,40 +104,40 @@ flipbip_strtok_r(char *s, const char *delim, char **last)
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
void
flipbip_strrev(unsigned char *str)
{
int i;
int j;
unsigned char a;
unsigned len = strlen((const char *)str);
for (i = 0, j = len - 1; i < j; i++, j--)
{
a = str[i];
str[i] = str[j];
str[j] = a;
}
}
int
flipbip_itoa(int num, unsigned char* str, int len, int base)
{
int sum = num;
int i = 0;
int digit;
if (len == 0)
return -1;
do
{
digit = sum % base;
if (digit < 0xA)
str[i++] = '0' + digit;
else
str[i++] = 'A' + digit - 0xA;
sum /= base;
}while (sum && (i < (len - 1)));
if (i == (len - 1) && sum)
return -1;
str[i] = '\0';
flipbip_strrev(str);
return 0;
}
// void
// flipbip_strrev(unsigned char *str)
// {
// int i;
// int j;
// unsigned char a;
// unsigned len = strlen((const char *)str);
// for (i = 0, j = len - 1; i < j; i++, j--)
// {
// a = str[i];
// str[i] = str[j];
// str[j] = a;
// }
// }
// int
// flipbip_itoa(int num, unsigned char* str, int len, int base)
// {
// int sum = num;
// int i = 0;
// int digit;
// if (len == 0)
// return -1;
// do
// {
// digit = sum % base;
// if (digit < 0xA)
// str[i++] = '0' + digit;
// else
// str[i++] = 'A' + digit - 0xA;
// sum /= base;
// }while (sum && (i < (len - 1)));
// if (i == (len - 1) && sum)
// return -1;
// str[i] = '\0';
// flipbip_strrev(str);
// return 0;
// }
4 changes: 2 additions & 2 deletions helpers/flipbip_string.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
char * flipbip_strtok(char *s, const char *delim);
char * flipbip_strtok_r(char *s, const char *delim, char **last);
void flipbip_strrev(unsigned char *str);
int flipbip_itoa(int num, unsigned char* str, int len, int base);
// void flipbip_strrev(unsigned char *str);
// int flipbip_itoa(int num, unsigned char* str, int len, int base);
Loading

0 comments on commit 8ea4843

Please sign in to comment.