Hi guys, here is my code that am working on this morning, and I came across a point when pointer operation went wrong.
#include<stdio.h>
int main(){
char a[20]="Hello World !!!";
char *ptr=a;
FILE *p;
p=fopen("new.txt", "w");
int i;
for (i=0; *ptr != '\0'; i++){
fprintf(p,"%c", ptr[i]);
}
fclose(p);
getch();
return 0;
}
Initially I printed output on console, but then I was missing some lines. Thats why I decided to save it in a text file. Following is a snapshot of same as I was not able to upload .txt file here.
My question here is why after detecting a \0 character loop didn't terminated ?