Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:36:11+00:00 2026-05-26T02:36:11+00:00

I have a string in my function defined like .. char *key=anyvalue; Now I

  • 0

I have a string in my function defined like ..

 char *key="anyvalue";

Now I use a linux command as …

 $openssl dgst -md5 -hmac "anyvalue" file.txt

Now the problem is I need to carry out following task through a C function ..

Here is the code …

  void func (char *key) {

     char *key_new=key;

     system("openssl -dgst md5 -hmac <got stuck here> file.txt");

  }

How could I pass the key value to the portion labled ??

I did this pretty simply in php. …

   $key="somevalue"

   exec("openssl -dgst md5 -hmac $key file.txt");

Is there something similiar avaliable in C ???

If not then Please tell me any other possible way ???

Limitation :

The key has to be passed through function .

I can’t take it as a C command line argument.

Edit :

I tried with this one … but first of all I would like to mention that its a small file in a big project and warning being treated as error .. so I need to take care of them also

Here is what I did –

    char *sstring=NULL;
    sprintf(sstring, "openssl dgst -md5 -hmac \"%s\"
    -out data3.md5 data3.txt",(char *)key);
    system(sstring);

if I won’t initialize then here comes the warning ..

    gcc -o hmacmd5.so -I.. -fPIC -fsigned-char -pipe -Wall 
    -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wnested-externs
    -Winline -Werror -g -Wcast-align -DSENDIP_LIBS=\"/usr/local/lib/sendip\"
    -shared hmacmd5.c ../libsendipaux.a ../libsendipaux.a

    cc1: warnings being treated as errors
    hmacmd5.c: In function ‘xoricv’:
    hmacmd5.c:271:9: error: ‘sstring’ is used uninitialized in this function
    make: *** [hmacmd5.so] Error 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:36:11+00:00Added an answer on May 26, 2026 at 2:36 am

    I think you are looking for sprintf:

    int sprintf(char *STR, const char *FORMAT, ...);
    

    In your case, you would use it as follows:

    sprintf(some_allocated_output_string, "openssl -dgst md5 -hmac %s", key);
    system(some_allocated_output_string);
    

    EDIT:

    After seeing the code you tried, I can see I didn’t provide you a complete answer.

    You have two choices here (assume that STRING_SIZE below is some #defined size, like 300 or something):

    1) use a preallocated buffer:

    char sstring[STRING_SIZE];
    sprintf(sstring, "openssl -dgst md5 -hmac \"%s\" -out data3.md5 data3.txt",(char *)key);
    system(sstring);
    

    2) use malloc/free:

    #include <stdlib.h>
    //blah blah blah
    char *sstring=NULL;
    //blah blah blah
    sstring = malloc(STRING_SIZE);
    sprintf(sstring, "openssl -dgst md5 -hmac \"%s\" -out data3.md5 data3.txt",(char *)key);
    system(sstring);
    free(sstring);
    

    I would suggest the first approach. Along with this, I would highly suggest taking care to use @pmg’s suggestion of snprintf, if your compiler supports it. This would look like this:

    char sstring[STRING_SIZE];
    int result = 0;
    result = snprintf(sstring, STRING_SIZE, "openssl -dgst md5 -hmac \"%s\" -out data3.md5 data3.txt",(char *)key);
    // Perform a check on result here, in case you ran out of space.
    // If result > STRING_SIZE, you need to try a larger buffer.
    system(sstring);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of strings defined like this: char** arrNames; Now I want
I have a function in a native DLL defined as follows: #include <string> void
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have a function that takes a string-like argument. I want to decide if
I have a struct where a constant char string is defined and a pointer
I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
I have a connection string being passed to a function, and I need to
I have a function which parses one string into two strings. In C# I
I have a function called: void initializeJSP(string Experiment) And in my MyJSP.h file I
I have a function which accepts a string parameter such as: var1=val1 var2=val2 var3='a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.