We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to send control codes to a printer they look like this :
unsigned char cntrl_codes[6] = { 0x0d, 0x14, 0x1b, 0x4c, 0x0d, 0x0d};
//this function takes two arguments // 1)the array // 2)time delay between successive codes void print(unsigned char* c,unsigned char del) { int x,y; y=strlen(c);//y++; for(x=0;x<y;x++) { putchar(c[x]); delay(del); } }
1) strlen does not give correct result 2) trailing zero ... to make it NULL terminated ...why? 3) i want a generalized func that can take arrays of different lengths.... 4) so should I use 'strlen' in my main func to find size of array and then pass it as argument ? how would that change it ? Thanks Mandar Limaye
strlen uses the trailing zero to find the length of the string. It could be implemented like this:
int strlen(const char* str) { int len = 0; while ( *str++ ) len++; return len; }