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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:50:41+00:00 2026-06-01T01:50:41+00:00

void print(part *item, int part_count) { int i=0; for (i=0; i<part_count; i++) { printf(Item

  • 0
void print(part *item, int part_count) {
    int i=0;

    for (i=0; i<part_count; i++) {
       printf("Item number: %d\n", i + 1);
       printf("Item name: %s\n", item[i].name);
       printf("Item price: $%f\n", item[i].price);
       printf("Item quantity: %d\n", item[i].quantity);
    }
}

i want to print an array of structs created with a different function. I have looked but have yet to find a different way to print them or what i am doing wrong in the print statements. My program compiles but crashes upon running.

ok well it is good to know the problem is not within these statements. That was frustrating me. here is the add function.

void add(part *item, int *part_count)
 {
      if (!item)
      {
         item = malloc(sizeof(part));
      }

      item = realloc(item, sizeof(part) * *part_count + 1);

      item[*part_count].name = malloc(sizeof(char)*64); // max of 64 characters

      printf("Please enter item name: ");
      scanf("%65s", item[*part_count].name);

      printf("Please enter item price: ");
      scanf("%f", &item[*part_count].price);

      printf("Please enter item quantity: ");
      scanf("%d", &item[*part_count].quantity);

      *part_count = *part_count+ 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-06-01T01:50:42+00:00Added an answer on June 1, 2026 at 1:50 am
    void add(part **item, int *part_count)
    {
      char temp[100];
    
      if (!(*item)){
       //printf("first alloc\n");
           *item = malloc(sizeof(part)*3);
      }
      else if (*part_count>= 3){
      //printf("realloc\n");
          *item = realloc(*item, sizeof(part) * (*part_count + 1));
      }
    
      item[0][*part_count].name = malloc(sizeof(char)*100); // max of 100 characters
    
      printf("Please enter item name: \n");
      fgets(temp, 100, stdin);     
      strcpy(item[0][*part_count].name, temp);      
    
    
      printf("Please enter item price: \n");
      fgets(temp, 100, stdin);
      sscanf(temp, "%f", &item[0][*part_count].price);      
    
    
      printf("Please enter item quantity: \n");
      fgets(temp, 100, stdin);
      sscanf(temp, "%d", &item[0][*part_count].quantity);   
    
    
      *part_count = *part_count+ 1;
    }
    

    This ended up doing it. Not sure if using a **struct was necessary but was the only method I could get working.

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

Sidebar

Related Questions

public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
Suppose I have class A { public: void print(){cout<<A; }}; class B: public A
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<
When I write the following program: file 1: #include <stdio.h> int global; void print_global1()
1167 ptr = (void*)getcwd(cwd, MAX_PATH_LENGTH-1); (gdb) n 1168 if (!ptr) { (gdb) print ptr
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
My Program overrides public void paint(Graphics g, int x, int y); in order to
I have a code that uses Arrays.sort(char[]) in the following manner: void arrayAnalysis(String[] array){
As part of a homework assignment, we are supposed to create an array that

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.