This blog is under construction

Saturday, 29 June 2013

C program to access string using pointers

Write a C program to access string using pointers.


  #include <stdio.h>
  #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



1 comment:

  1. Nice tutorial. Thanks for sharing the valuable info about c Training. it’s really helpful. Who want to learn c language this blog most helpful. Keep sharing on updated tutorials…..

    ReplyDelete