dimanche 29 mars 2015

C function to print the alphabet using pointers



I have this code:



void printArray(char* p, int len)
{
for( p ; p < p + len ; p++ )
{
printf("%c", *p);
}
printf("\n");
}

int main()
{
char* abc = "abcdefghijklmnopqrstuvwxyz";
printArray(abc, 26);
return 0;
}


That is suppose to print all the English alphabet letters, but there is a run-time error and I need to find why it is caused and how to fix it. I have tried anything that came up to my mind to fix it but nothing helped, it just prints a lot of random stuff. Thanks for the help in advance. P.S: This is not a code I wrote, I just need to find the mistake and fix it.




Aucun commentaire:

Enregistrer un commentaire