Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <stdio.h>
#include <string.h>
#include <conio.h>

typedef struct 
{
    char name[10];
    int age;
}detailsStruct;

static int fnProcess(detailsStruct** detailsPtrPtr)
{
    detailsStruct detailsStr;

    strcpy_s(detailsStr.name,"Arjun");
    detailsStr.age = 25;

    *detailsPtrPtr = &detailsStr; 


    return 0;
}

int main()
{
    int rv = 0;
    detailsStruct* detailsPtr;

    rv= fnProcess(&detailsPtr);

    printf("\n Name %s", detailsPtr->name);
    printf("\n Age %d", detailsPtr->age);
    _getch();
    return rv;
}

Here is the output I am getting:

Name Arju£²▲
Age 221459990
Posted
Updated 8-Feb-10 6:29am
v4

1 solution

You appear to have two problems:
1. The strcpy_s() function takes three parameters, check the documentation.
2. detailsStr in the fnProcess() function is a local variable and so goes out of scope when you return. Using its address after the return is likely, at the least, to produce incorrect results, and possibly crash your program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900