Wednesday, 15 May 2013

c - Stop string array -



c - Stop string array -

how stop sting array. if set maximum 40 char can put, dont want fill whole string 40 char. here code write char @ string array.

int main(void) { char data[1][40]; int i1 = 0; int i2 = 0; serial_init(); while (1) { (i1=0;i1<1;i1++) { (i2=0;i2<40;i2++) { data[i1][i2] = usart_receive(); } } (i1=0;i1<1;i1++) { (i2=0;i2<40;i2++) { usart_transmit(data[i1][i2]); } } } homecoming 0; }

example if force if (usart_receive() == '.'). function stop string fill until 40 char. how that, hope can help me out here.

(i1=0;i1<1;i1++) { (i2=0;i2<40;i2++) { data[i1][i2] = usart_receive(); if (data[i1][i2] == '.') { if (i2 < 39) data[i1][i2+1] = '\0'; // null terminate string break } } }

this stop receive on '.', null terminate string (if needed), , break out of loop.

c arrays string avr uart

No comments:

Post a Comment