Конвертация числовых типов в строку
This commit is contained in:
		
							parent
							
								
									08e39eca09
								
							
						
					
					
						commit
						f9a5352b6e
					
				| @ -1,12 +1,23 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| // -------------------------------------
 | ||||
| // BASE - String and init of this
 | ||||
| // -------------------------------------
 | ||||
| typedef char* string; | ||||
| string strInit(char* s) { | ||||
| 	string str = malloc(strlen(s) * sizeof(char)); | ||||
| 	strcpy(str, s); | ||||
| 	return str; | ||||
| } | ||||
| // -------------- END ------------------
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // -------------------------------------
 | ||||
| // FUNCTION - basic operations
 | ||||
| // -------------------------------------
 | ||||
| void strAdd(string* s, char* str_new) { | ||||
| 	*s = realloc(*s, strlen(*s) + strlen(str_new)*sizeof(char)); | ||||
| 	strcat(*s, str_new); | ||||
| @ -18,3 +29,26 @@ void strSet(string* s, char* str_new) { | ||||
| void strCopy(string* s1, string* s2) { | ||||
| 	strcpy(*s2, *s1); | ||||
| } | ||||
| // -------------- END ------------------
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // -------------------------------------
 | ||||
| // CONVERT - different convert to str
 | ||||
| // -------------------------------------
 | ||||
| char* int2Str(int* num) { | ||||
|     char* buffer = malloc(12); | ||||
|     sprintf(buffer, "%d", *num); | ||||
|     return buffer; | ||||
| } | ||||
| char* float2Str(float* num) { | ||||
|     char* buffer = malloc(12); | ||||
|     sprintf(buffer, "%f", *num); | ||||
|     return buffer; | ||||
| } | ||||
| char* double2Str(double* num) { | ||||
|     char* buffer = malloc(12); | ||||
|     sprintf(buffer, "%f", *num); | ||||
|     return buffer; | ||||
| } | ||||
| // -------------- END ------------------
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user