Run-Time Check Failure #2 - Stack around the variable 'letterarray' was corrupted.

Started by
1 comment, last by DevFred 16 years, 1 month ago
I've been trying to figure this stack corruption issue.I know the corruption comes from writing outside the allocated buffer in memory.However,I couldn't understand where ? #include <stdio.h> main(){ int letterarray[25]; int n,i,c; for(i=0;i<26;i++) letterarray=0; while((c=getchar())!='*') letterarray[c-97]++; for(n=0;n<26;n++) {putchar('a'+n);printf(" ");} printf("\n"); for(i=0;i<26;i++) printf("%d ",letterarray); }
Advertisement
Your letter array is 25 elements, but you write 26.
An array[size] has valid indices 0 to size-1. size itself is not a valid index.

This topic is closed to new replies.

Advertisement