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

  • Home
  • SEARCH
  • 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 6741619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:44:45+00:00 2026-05-26T11:44:45+00:00

I hava a C function like this .. func(uint8_t *key,uint8_t keylen) { FILE *fk;

  • 0

I hava a C function like this ..

func(uint8_t *key,uint8_t keylen) {

FILE *fk;
fk=fopen("akey","wb");
fwrite((char *)key,keylen,1,fk);

puts((char *)key); // for testing

fclose(fk);

sprintf(sstring,"... \"%s\" ... ",(char *)key);
        // ...other irrelevant stuff for here
system(sstring);


}

I want the key provided as input to be used at the
place marked \"%s\" in sprintf command

Input :

  Key=qwerty

Output :

 $cat akey
 qwerty

and output of puts((char *)key) is –

 qwerty�    

 // include newline character as well

Suggest me on this , I tried with this (at their respective position in the code)
but getting segmentation fault

    char *p;
    memcpy(p,(char *)key,keylen);
    puts((char *)p);
  • 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-26T11:44:45+00:00Added an answer on May 26, 2026 at 11:44 am

    You could use the form %.*s to print it out:

    printf("%.*s\n", (int)keylen, (char *)key);
    ...
    sprintf(sstring,"... %.*s ... ", ... (int)keylen, (char *)key ...);
    

    Here an extract from the Wikipedia entry on printf:

    The width and precision formatting parameters may be omitted, or they
    can be a fixed number embedded in the format string, or passed as
    another function argument when indicated by an asterisk “*” in the
    format string. For example printf(“%*d”, 5, 10) will result in ” 10″
    being printed, with a total width of 5 characters, and printf(“%.*s”,
    3, “abcdef”) will result in “abc” being printed.

    NOTE: Using an 8-bit type (uint8_t) to represent the length limits the length of the string to 255 characters. Better is to use size_t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hava a function that looks something like this: require(config.php); function displayGta() { (...
I hava a java program, a section of it is compute intensive, like this
I hava a CSV file that I want to treat as source code. Essentially
hi i hav a code like this in the end i m getting error
I hava a perl subroutine where i would like to pass parameters as a
I'd like to hava a Dojo dojox.grid.DataGrid with its data from a servlet. Problem:
I hava a xml doc (and complex element) that is similar to this example:
I hava an unordered List navigation and i wanted to transform this to JSF
I hava some UILabel in UITableViewCell. My purpose is to call a function when
I hava a remote validator setup like so remote: { type: POST, url: /some/url,

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.