having got my head around arrays (for the next 4 seconds till i go thick again) i am wondering about the return value from strlen
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char mystring[40] = "hello";
printf("the length of \"my string\" is %lu\n", strlen(mystring));
return 0;
}
this returns 5 as one would expect (5 letters but doesn't count the "\0" character).
however if i do this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char mystring[40] = "\e[196;5;196m\e[38;5;196mhello\e[0m";
printf("the length of \"my string\" is %lu\n", strlen(mystring));
return 0;
}
i count 35 characters but lenstr returns 32. if its ignoring the \e parts i make the count 29 so it cant be that. what has happened to the "missing" 3 characters and when deciding on the length of an array to hold these escape codes and message what do i declare the array length as 36 or 33 including the null.
many thanks
coop