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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:15:52+00:00 2026-05-28T07:15:52+00:00

i have to make a program which can accept input like this: 2012-01-20 10:50:52

  • 0

i have to make a program which can accept input like this:

2012-01-20 10:50:52 127.0.0.1(via UDP: [127.0.0.1]:65008->[0.0.0.0]:0) TRAP, SNMP v1, community telros
        SNMPv2-SMI::enterprises.3.1.1 Enterprise Specific Trap (1) Uptime: 73 days, 21:16:00.11

2012-01-20 10:50:53 127.0.0.1(via UDP: [127.0.0.1]:57487->[0.0.0.0]:0) TRAP, SNMP v1, community telros
        SNMPv2-SMI::enterprises.3.1.1 Enterprise Specific Trap (1) Uptime: 73 days, 21:16:01.15

2012-01-20 10:50:54 127.0.0.1(via UDP: [127.0.0.1]:34207->[0.0.0.0]:0) TRAP, SNMP v1, community telros
        SNMPv2-SMI::enterprises.3.1.1 Enterprise Specific Trap (1) Uptime: 73 days, 21:16:01.92

and then put it into Postgres: get two lines devided by empty (\n) line and put it into db table.

what i’m trying to do is:

const char *conninfo;
const char *paramValues[1]; 
char *str;
char *sql;
...
while(fgets(str, 126, stdin)) {

        if (0 != strcmp(str,"\n")){
        strcat(sql,str);
        }else{
        paramValues[0] = (const char *)sql;
        res = PQexecParams(conn,
            "insert into traps (trap_content, trap_timestamp) values ($1, localtimestamp);",
            1,
            NULL,
            paramValues,
            NULL,
            NULL,
            1);
        sql = "";
        }
    }

but paramValues[0] seems to be empty on insert and empty line appears in the table.

how can i get two strings before the empty one in paramValues[0]?
i’m not good in C, so sorry if it’s silly question =)

  • 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-28T07:15:53+00:00Added an answer on May 28, 2026 at 7:15 am

    This line:

    sql = "";
    

    will cause the char* variable ‘sql’ to point at the address of the string literal “”. It’s incorrect to then call strcat(sql,str) with sql now pointing to the address of this literal; that could even segfault. Try instead:

    strcpy(sql, "");
    

    or equivalently

    sql[0] = 0
    

    Also, you don’t show where ‘sql’ is defined, but it has to point to a buffer big enough to hold as many adjacent lines as you expect to encounter.

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

Sidebar

Related Questions

Ok, let's see if I can make this make sense. I have a program
I have my main program window, and I would like to make a foldable
I have written a program which takes a file as input and whenever it
I want to make connection between two parts of my program which can be
So I got this task to make a program which will allow the user
Lets say I have a server program that can accept connections from 10 (or
I have a program that prints the cube and which can be rotated. Here's
I have a java program that launches a program on start up. This can
I have a few questions related: 1) Is possible to make my program change
I have a little program that I want to make open automatically when my

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.