This code is for declaring and printing a string using pointer concept
char *strPtr = "HelloWorld";
// temporary pointer to iterate over the string
char *temp = strPtr;
while (*temp != '\0')
{
printf("%c", *temp);
temp++;
}
In this code I just want to replace the while loop to for loop. But when trying the code does not give any output. My code is as follows
char *name = "SAMPLE NAME";
int i;
for (i = 0; name[i] != '\0'; i++)
{
printf("%c", *name);
}
This code Does Not work. [Gives blank output] Where is the error ??