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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:29:15+00:00 2026-06-08T22:29:15+00:00

vector_int.h is a header with self-made dynamic array (vector) structure. test.c is a testing

  • 0

vector_int.h is a header with self-made dynamic array (vector) structure.

test.c is a testing programm.

All code is bellow:

vector_int.h:

#include <stdio.h>

typedef struct 
{
    long int len; // Length
    int *array;   // Dynamic Array
} IntVector; 

void ResizeIntVector(IntVector *vector, int size) // Resizing of vector
{
    realloc(vector->array, size * sizeof(int));
    vector->len = size; // Changing of length variable
}

void SetIntVectorCell(IntVector *vector, unsigned int cell_number, int cell_value) // Put cell_value in array[cell_number]
{
    if (cell_number >= vector->len)
        ResizeVectorInt(&vector, cell_number); // Grow size of memory if it's not enough

    vector->array[cell_number] = cell_value;
}

test.c:

#include "vector_int.h"
#include <stdio.h>

int main()
{
    IntVector vector;

    int n;
    scanf("%d", &n);

    int i;
    for (i = 0; i < n; i++) // testing
    {
        SetIntVectorCell(&vector, i, i);
        printf("%d ", vector.array[i]);
    }

    return 0;       
}

Logs:

1   0   D:\Work\Raspberry Pi\test.c In file included from D:\Work\Raspberry Pi\test.c
        D:\Work\Raspberry Pi\vector_int.h   In function 'ResizeIntVector':
11  2   D:\Work\Raspberry Pi\vector_int.h   [Warning] incompatible implicit declaration of built-in function 'realloc' [enabled by default]
            [Linker error] C:\Users\ALEXAN~1\AppData\Local\Temp\cccFKqxs.o:test.c:(.text+0x4a): undefined reference to `ResizeVectorInt'
            collect2: ld returned 1 exit status

I think that there is error in using realloc function, but I thought that I did all right.
Please help me and find a mistake or mistakes.

  • 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-08T22:29:16+00:00Added an answer on June 8, 2026 at 10:29 pm

    You have a few problems:

    • The implicit declaration/realloc problem is because you need to include stdlib.h for the realloc signature. Without a function signature the compiler will make some assumptions about your function arguments and return value, then during linking, the linker complains about this if these assumptions don’t match the actual function implementation.

    • You’re passing realloc an address that hasn’t been initialized. This is asking for trouble. Before using your vector variable, do some initialization:

      vector->array = NULL;
      vector->len = 0;
      
    • Furthermore, your usage of realloc is incorrect: it won’t change the actual pointer that you give it, only the size of the memory block pointed to. You need to re-assign the pointer yourself. Note that realloc can return NULL upon failure, so do something like:

      tmp = realloc(vector->array, size * sizeof(int));
      
      if (tmp != NULL)
      {
          vector->array = tmp;
          vector->len = size; // Changing of length variable
      }
      else handleAllocError();
      
    • Finally, don’t define your functions in the header. This will work, but it’s better to have an implementation file vector_int.c that defines the functions declared in the header.

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

Sidebar

Related Questions

I've got a class: someclass header code: class SomeClass{ SomeClass(); vector<int> somePointerVector; public: SomeClass(vector<int>
Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace
header.h #include <iostream> #include <vector> class CombatLine{ std::stringstream Line; std::vector<std::string> TokenLine; void SetLine(std::string s){
I have the following header file: #ifndef DATABASE_H #define DATABASE_H #include <vector> #include <iostream>
header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,
I've written a template function to determine the median of any vector or array
I found this vector template class implementation, but it doesn't compile on XCode. Header
I am running a very simple C++ program: #include <list> #include <vector> int main(int
Take a simple class with the big 3 (constructor, copy constructor, destructor): #include <vector>

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.