The following code runs fine with Pelles C but terminates on MSVC 2010 with an error message
"Run-Time Check Failure #2 - Stack around the variable 'c' was corrupted."
Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char s[20][20],*c[20];
FILE *fp;
int i,j,words;
fp=fopen("acc.txt","r");
words=i=0;
while(fscanf(fp,"%s",s[i])!=EOF)
{ words++; i++; }
for(i=0;i<words;i++)
c[i]=s[i];
for(i=1;i<words;i++)
{
for(j=1;j<=words-i;j++)
{
if(strcmp(c[j-1],c[j])>0)
{
c[20]=c[j-1];
c[j-1]=c[j];
c[j]=c[20];
}
}
}
fclose(fp);
fp=fopen("acc.txt","w");
for(i=0;i<words;i++)
fprintf(fp,"%s ",c[i]);
}
Can someone tell me whats wrong??