Mega Code Archive

 
Categories / C / Code Snippets
 

For loop a char array using pointer

#include <stdio.h> int main(void) { char str[] = "Pointers are fun and hard"; char *p; int j; p = str; /* loop until null is found */ for(j = 0; p[ j ]; j++) printf("%c", p[ j ]); return 0; }