- Enter a string to assign to the str string variable as follows:
printf("Enter a string: ");scanf("%s", str);
- Set a pointer to point at the string, as demonstrated in the following code. The pointer will point at the memory address of the string's first character:
ptr1=str;
- Find the length of the string by initializing an n variable to 1. Set a while loop to execute when the pointer reaches the null character of the string as follows:
n=1;while(*ptr1 !='\0'){
- Inside the while loop, the following actions will be performed:
- The pointer is moved one character forward.
- The value of the n variable is incremented by 1:
ptr1++;n++;
- The pointer will be at the null character, so move the pointer one step back to make it point ...