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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:26:53+00:00 2026-06-12T18:26:53+00:00

I’ve hit a wall with a program that uses embedded SQL to fetch rows

  • 0

I’ve hit a wall with a program that uses embedded SQL to fetch rows from a database table, stores the row data in a struct, and then has that data processed with results being stored in another struct and pushed to a linked list. The struct that where the fetch data is stored is as follows:

struct rowstruct {
    char    *first;
    char    *last;
    long    amt;
}   client;

and my struct that I use to store the processed data (and subsequently push as a node in my linked list) is like this:

struct mystruct {
        char    *firstN;
        char    *lastN;
        long    total;
    }   data;

My problem is that with each fetch loop that occurs, I need to copy the client.first and client.last values into data.firstN and data.lastN, but I can’t get it to work. The following, using the assignment operator, just seems to be copying the pointer, rather than the value:

data.firstN = client.first;
data.lastN = client.last;

If I output data.firstN and data.lastN after the first iteration of my loop, the values appear correct, but after the second fetch iteration, the first node in my list will reflect the values from the second fetch, rather than the first.

strcpy will compile, but fails at runtime due to segmentation fault, which from reading on here is due to the char* being used, though I don’t think I can use char[] or string when fetching the data using embedded SQL, so that seems like a dead end.

I’m sure there’s a way to do this, and it’s probably obvious to most here, but I’m at a loss. Any help would be appreciated.

Thanks!

  • 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-06-12T18:26:54+00:00Added an answer on June 12, 2026 at 6:26 pm

    If the code says to copy the pointer, that is exactly what happens.

    Probably what you want is something along the lines of

    data.firstN = strdup (client.first);
    data.lastN = strdup (client.last);
    

    There are more C++-ish ways of doing the same thing, but this should get you over the hump.


    You don’t need to re-declare the structure. Instead, you can declare data with

    struct rowstruct data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping 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.