If i was a beginner and wanted to use your instructions i might write something like this
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char* strPointer;
strcpy(strPointer,"Some boys thing they know everything...");
printf("%s\n",strPointer);
return 0;
}
output
Code:
Macintosh-c8bcc88e5669-9:~ usi$ pico px.c
Macintosh-c8bcc88e5669-9:~ usi$ gcc -Wall px.c -o px
Macintosh-c8bcc88e5669-9:~ usi$ ./px
Segmentation fault: 11
I hope you understand why in your case it worked
......
The loop counter was not a problem.You do not access all the elements. It is similar to have this
Code:
#include <stdio.h>
int main(void)
{
int array[5] = {0,1,2,3,4};
int i;
for(i = 0 ; i < 4 ; i++)
printf("%d\n",array[i]);
return 0;
}
output
Code:
Macintosh-c8bcc88e5669-9:~ usi$ pico px.c
Macintosh-c8bcc88e5669-9:~ usi$ gcc -Wall px.c -o px
Macintosh-c8bcc88e5669-9:~ usi$ ./px
0
1
2
3
But ok maybe you want this