Thread: assignment of pointer...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305

    Question assignment of pointer...

    Hi ,

    I am unable to debug what is going with this program of reversing a string.

    I had another doubt that is the assignment
    *a = *p
    valid because when i try to debug the program it gives error at this line in the program below that access violation writing at location whatever address is contained in a.


    insert
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void xstrrev(char *);
    
    int main(){
    
    	int i;
    	static char *s[] = {
    		"To err is human...",
    		"But to really mess things up...",
    		"One needs to know C!!"
    	};
    
    	for(i=0;i<3;i++){
    		xstrrev(s[i]);
    		printf("\n\r%s", s[i]);
    	}
    	return 0;
    }
    
    
    void xstrrev(char *a){
    
    	int len,j;
    	char *p, temp1, temp2;
    
    	//printf("\n\r%c %d", *a,a);
    	len = strlen(a);
    	//printf("\n\r%d %d", len, len/2);
    	p = a + len -1;
    	//printf("\n\r%d %c", p, *p);
    	for(j = 1;j<= len/2;j++){
    	
    		temp1 = *a;
    		temp2 = *p;
    		printf("\n\r %c %c",*p, *a);
    		*a = *p;
    		printf("\n\r1\t%c\t%c",*a,*p);
                    // *p = temp;
    		//printf("\n\r2\t%c\t%c", *p, temp);
                    ++a;
    		printf("\n\r3");
                    --p;
    		printf("\n\r4");
            }
    }
    Last edited by roaan; 07-08-2009 at 04:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  3. Replies: 3
    Last Post: 06-19-2004, 10:24 AM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. When do we get Null Pointer Assignment
    By YALINI in forum C Programming
    Replies: 1
    Last Post: 08-29-2001, 01:48 AM