As far as I know you C does not have intlen() function , at least not in the header files which you include your project. strlen() returns the length of string but for others, you have to decide the needed amount of space for char by your self. Beside of this to able to use pointer you need to specify a memory block; otherwise you cannot use pointer like the definition of yours char*string.To explain myself I attached two piece of code please check
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int intlen(int data4_allocate) {
return floor(log10(abs(data4_allocate))) + 1;
}
int main() {
char dayofweek[] = "Friday";
int day = 13;
char month[] = "May";
int year = 1927;
char *string; //I want to save my date into this string
const size_t *memory;
//trying to allocate memory
memory = (size_t*)malloc(strlen(dayofweek) + strlen(month) + intlen(day) +
intlen(year));
string = (char*)malloc(sizeof(memory)+1);
//trying to write my strings and ints into one string
snprintf(string, (size_t)memory, "%s der %d.%s %d\n", dayofweek, day, month,
year);
printf("%s\n", string);
free((char*)string);
return 0;
}
or you can define a macro which determines the maximum byte length of given numbers in that case your code might be like following code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main() {
#define MONTH_BYTE_SIZE 2 // 0 -- 12 max 2 char needed
#define DAY_BYTE_SIZE 2 // 0-31 max 2 char needed
#define YEAR_BYTE_SIZE 4 // 0--2999 max 4 char needed
char dayofweek[] = "Friday";
int day = 13;
char month[] = "May";
int year = 1927;
char *string; //I want to save my date into this string
const size_t *memory;
//trying to allocate memory
memory = (size_t*)malloc(strlen(dayofweek) + (sizeof(char)*MONTH_BYTE_SIZE) +
(sizeof(char) * DAY_BYTE_SIZE) + (sizeof(char) * YEAR_BYTE_SIZE));
string = (char*)malloc(sizeof(memory)+1);
//trying to write my strings and ints into one string
snprintf(string, (size_t)memory, "%s der %d.%s %d\n", dayofweek, day, month,
year);
printf("%s\n", string);
free((char*)string);
return 0;
}
the result should be like
