c++ - why should we not include the last array element in sprintf? -


i have code shown below, last statement works if use l_plates[i]. in below case throws error "passing argument 1 of 'sprintf' makes pointer integer without cast" if need loop n too. should use element if use sprintf? please explain. in advance.

char type, letters[4], digits[5]; char l_plates[m][n];  (i=0; i<m; i++) {     scanf(" %c", &type);     scanf("%3s", letters);      scanf("%4s", digits);      sprintf(l_plates[i][n], "%s %s %c", letters, digits, type); } 

i see 2 problems here. first, first argument of sprintf should char*, not char, you're sending it.

secondly, array of size n indexed 0 n - 1. trying access element n, you're stepping outside of array. last element [n - 1].


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -