Write a C program to access string using pointers.
#include <string.h>
int main() {
char str[100], *ptr;
int i;
/* get the input string from the user */
printf("Enter your input:\n");
fgets(str, 100, stdin);
str[strlen(str) - 1] = '\0';
/* ptr points to str address */
ptr = str;
/* accessing string using pointer */
while (*ptr != '\0') {
printf("%c", *ptr);
ptr++;
}
printf("\n");
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input:
see-programming.blogspot.com
see-programming.blogspot.com
Enter your input:
see-programming.blogspot.com
see-programming.blogspot.com
No comments:
Post a Comment