Advertisement
LordJakub

Untitled

Feb 5th, 2024
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6.  
  7. void ___chkstk_ms(void *target_location);
  8. void __chkstk(void *target_location) {
  9.     ___chkstk_ms(target_location);
  10. }
  11. //Most of that was written by ChatGPT, I don't know enough C to do it myself.
  12. char* IntToString(int num) {
  13.     int len = snprintf(NULL, 0, "%d", num);
  14.    
  15.     char* str = (char*)malloc(len + 1);
  16.    
  17.     snprintf(str, len + 1, "%d", num);
  18.    
  19.     return str;
  20. }
  21.  
  22. char* FloatToString(float num) {
  23.     char* str = (char*)malloc(20 * sizeof(char)); // allocate memory for string
  24.     sprintf(str, "%f", num); // convert float to string
  25.     return str;
  26. }
  27.  
  28. int FloatToInt(float num) {
  29.     return (int)num; // implicit conversion from float to int
  30. }
  31.  
  32. int StringToInt(char* str) {
  33.     return atoi(str); // convert string to int
  34. }
  35.  
  36. float StringToFloat(char* str) {
  37.     return atof(str); // convert string to float
  38. }
  39. char* Read() {
  40.     char* input = (char*)malloc(100 * sizeof(char));
  41.     if (input == NULL) {
  42.         exit(1);
  43.     }
  44.     scanf("%s", input); // read input from command line
  45.     return input;
  46. }
  47.  
  48.  
  49. char* append(char* str1, char* str2) {
  50.     char* result = malloc(strlen(str1) + strlen(str2) + 1);  
  51.     strcpy(result, str1);  
  52.     strcat(result, str2);  
  53.     return result;
  54. }
  55.  
  56.  
  57. void print(const char text[]) {
  58.     printf("%s\n", text);
  59. }
  60. void delay(int milliseconds) {
  61.     clock_t end_wait;
  62.     end_wait = clock() + milliseconds * (CLOCKS_PER_SEC / 1000);
  63.     while (clock() < end_wait) {}
  64. }
  65.  
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement