Return char array from function

Hi,

I am developing a " .a " library file. Inside of that library there are some functions. I have an encryption function for encrypt some text data. My problem is I am passing the plain data as char array into the function. After encrption process done I want to return it as a char array but it's not return.

My code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

int encrypt(char *plainData, char *encryptData){
   
   int status;
   
    // encrpypting...

   Print(encryptData); // encrypted data is printing well

   return status;

}

int main(){
   char encryptedData[300];
   char plainData[] = "1234567890";
   
   if(0 < encrypt(plainData,encryptedData)){
       
       Print(encryptedData); // Output is 0000000000000
       
   }
}


Please help.

thank you.
Any comment ???
Well in the code you have given you haven't populated the char[] encryptedData with anything. If I just do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;

void Print(char* data)
{
	cout << data << endl;
}

int encrypt(char* plainData, char* encryptData)
{   
   int status(1);
    // encrpypting...
	strcpy(encryptData, "encrypted data");

   Print(encryptData); // encrypted data is printing well

   return status;
}

int main()
{
   char encryptedData[300];
   char plainData[] = "1234567890";
   
   if(0 < encrypt(plainData, encryptedData))
	{
       Print(encryptedData); // Output is 0000000000000
   }
}


All is fine. If I were you I would use std::string. Then you would need to pass by reference.
Hi,

Thanks for the reply. In my case I am using " C " as my programming language. Any idea??

Thank you.
In my case I am using " C " as my programming language. Any idea??


Well, if you were to populate the char array as I did above, you should be fine.
Hi,

Before I make the " .a " file it is working properly. After make it, link it into my project, compile and install into POS terminal then it's not working. I don't know what to do.

Thank you.
Are you sure you are populating your char array named encryptData in the encrypt(...) function? How about writing the value of this variable out to a file?
Topic archived. No new replies allowed.