Usually we will do like this:
char szString[100]={0};
scanf("%s",szString);
for(int i = 0; i <strlen(szString); i++);
{
printf("%c",szString[i];
}
without knowing strlen(), we can print the same thing as below:
char szString[100]={0};
scanf("%s",szString);
for(int i = 0; szString[i]; i++);
{
printf("%c",szString[i];
}
if szString reaches NULL, it will returns zero, so for loop will be
terminated for that case.
No comments:
Post a Comment