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 4051990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:15:50+00:00 2026-05-20T14:15:50+00:00

I have the following: nodeID = abcde.abc.edu_12345 and I need to append the an

  • 0

I have the following:
nodeID = abcde.abc.edu_12345
and I need to append the an underscore and a 10digit value returned by time() to create the following:
node_inst_ID = abcde.abc.edu_12345_1016320007
where 1016320007 is the 10 digit value returned by time(). I am trying the following code but it doesnt seem to work:

#define NODE_ID_LENGTH 20
#define NODE_INST_ID 31
char nodeID[NODE_ID_LENGTH]
char node_inst_ID[NODE_INST_ID];
int main()
{
    /*
    Building of nodeID is a bit complex. So its hard to put all the code here. But printing the following at this point gives this
          for(int i = 0; i < NODE_ID_LENGTH; i++)
            {
              printf("%c", nodeID[i]);
            }
    gives
    abcde.abc.edu_12345
    If you need to know any more info about nodeID, I can post the print out of things that you suggest. 
    */

    long int seconds = time(NULL);
    char buf[10];
    sprintf(buf, "%ld", seconds);
    snprintf(&node_inst_ID[0], 20, "%s", &nodeID[0]);
    node_inst_ID[20] = '_';
    node_inst_ID[21] = '\0';
    cout<<"Node instance ID = "<<node_inst_ID<<endl;

    /* 
    I havent yet added the code for appending the time stamp. But I am expecting a print out for the above code like this:
    Node instance ID = abcde.abc.edu_12345_
    But the code is printing only
    Node instance ID = abcde.abc.edu_12345
    It is not adding the underscore at the end. 
    */
}

Can anyone point out what the mistake is? Thanks in advance.

  • 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-20T14:15:51+00:00Added an answer on May 20, 2026 at 2:15 pm
    snprintf(&node_inst_ID[0], 20, "%s", &nodeID[0]);
    node_inst_ID[20] = '_';
    node_inst_ID[21] = '\0';
    

    This assumes that the string is exactly 20 characters long – it isn’t. Try this:

    snprintf(&node_inst_ID[0], 20, "%s", &nodeID[0]);
    strcat(node_inst_ID, "_"); // strcat is safe in this context, usually you should use strncat.
    

    EDIT: If you want to still use snprintf, the easy way is:

    int len = strlen(node_inst_ID);
    snprintf(node_inst_ID + len, sizeof(node_inst_ID) - len, "%whatever", the, args);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following data: NodeId ExternalIds 50 601 56 700,701
Following SQL get what I need: SELECT TOP (50) [nodeId] FROM [dbo].[cmsContentXml] WHERE [xml]
I have a table called dbo.Node: NodeID int ParentNodeID int Title The following functions
Hi I have a dataset in the following format: NodeID | NodeName | NodeAttribute1
I have a Hierarchical Table for Categories in this form NodeID ParentID NodeName Following
I have following POJO`s: - Company Node (nodeID, company) User (userID, node) I want
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
i would need to store in a javascript variable the following table: Nodeid parentid
I have the following code: $stmt = $db->prepare(SELECT LATITUDE, LONGITUDE FROM NODEGEOLOCATION WHERE NODEID

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.