Results 1 to 2 of 2

Thread: Pointer not working properly with string

  1. #1
    Member
    Join Date
    Jun 2011
    Location
    India
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Pointer not working properly with string

    Hello friends please look at this program, this program does not give any compilation error but pointer p2 not working here correctly

    Code:
    /* Created By Ravinder Kumar ,Pointer with string*/
     #include<stdio.h>
     #include<stdlib.h>
     #include<string.h>
    int main()
    {
    char *p1;
    char *p2;
    char line1[50]="Hello i am rinku from ropar";   
    char line2[50];
    puts(line1);     /* This is okay and print the line1 */
    p1=line1;
    puts(p1);       /* This is also okay and print the line1 */
    p2=line2;
    putchar('\n');
    while(*p1 != '\0')
    {
    *p1++ = *p2++; 
    }
    *p2='\0';
    puts(line2);   /* Actual error is here  because  No error is coming and nothing is printed but this statement is okay*/
    return 0; 
     }
    Complition 0 error and 0 warning
    [/CODE]
    OUTPUT
    Code:
    Hello i am rinku from ropar
    Hello i am rinku from ropar

    Error with line2 string mean "char line2[50];" and after copy pointer first into pointer second nothing print in line2 which is pointed by pointer 2
    Last edited by rinkujames; 9th March 2012 at 02:01 PM.

  2. #2
    Member
    Join Date
    Jun 2011
    Location
    India
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    it has solved

    in while loop *p1++=*p2++; should have *p2++=*p1++;
    Last edited by rinkujames; 9th March 2012 at 02:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 12th October 2011, 08:56 PM
  2. chmod -R not working properly
    By kumarat9pm in forum File Servers
    Replies: 5
    Last Post: 22nd February 2010, 08:30 AM
  3. Problem on mouse pointer freezing
    By satimis in forum Mail Servers
    Replies: 0
    Last Post: 6th September 2008, 11:57 AM
  4. Spamassassin URI rule not working properly
    By diptanjan in forum Mail Servers
    Replies: 2
    Last Post: 26th June 2007, 12:11 PM
  5. UID's not mapping properly
    By marros in forum Linux software
    Replies: 1
    Last Post: 25th October 2006, 09:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •