I am trying to reverse a word using pointers but the problem that the following line cause error:access violation writting location
0x000...

*temp = *(n+len);

the full code

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<string.h>
void re(char *n){
    int len = strlen(n);
    char *temp=NULL;
    while (len != 0){
        *temp = *(n+len);
        len--;
        temp++;
    }
    n = temp;
}


void main(){

    char name[] = "yahia";
    re(name);
    printf("%s \n", name);

    system("pause");
}

*microsoft compilar
any help ?

ok , i figured the solution ,if any one is interested!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void re(char *n){
    int len = strlen(n);
    char localArray[10];
    char *temp = localArray; /*the problem was i inialized it to null and this is not correct as i store in no location in mem*/
    int size = len--; /*to avoid the null terminal for proper memcpy operation*/
    while (len >= 0){
        *temp = *(n + len);
        len--;
        temp++;
    }
    memcpy(n, localArray, size);
}

char name[] = "yahia";
void main(){
    printf("%s \n", name);
    re(name);
    printf("%s \n", name);
    system("pause");
}

Qualified tutors are ready to provide you Statistics Homework Help, Accounting Homework Help & assistance with all other subjects including College Finance, Economics Assignments. You can also contact us for your Dissertation, Thesis or your other writing needs. Best Prices, Fast Response!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.