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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:03:58+00:00 2026-06-02T13:03:58+00:00

I’ve been trying to include C Igraph libraries in c++(On eclipse), this code works

  • 0

I’ve been trying to include C Igraph libraries in c++(On eclipse), this code works good if you comment print_vectorList(&vn1, stdout) you get

cout<<VECTOR(v2)[0]<<endl------------>3        
cout<<VECTOR(v2)[1]<<endl------------>7

and if you don’t comment print_vectorList(&vn1, stdout) you get

 0 1 4 9
 1 0 7 9
 2 3 5 9
 3 2 6 9
 4 0 5 8
 5 2 4 8
 6 3 7 8
 7 1 6 8
 8 4 5 6 7
 9 0 1 2 3

with

cout<<VECTOR(v2)[0]<<endl------------>0        
cout<<VECTOR(v2)[1]<<endl------------>0

What’s wrong?

#include <igraph.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>





using namespace std;


void print_vector(igraph_vector_t *v, FILE *f) {
  long int i;
  for (i=0; i<igraph_vector_size(v); i++) {
    fprintf(f, " %li", (long int) VECTOR(*v)[i]);
  }
  fprintf(f, "\n");
}

void print_vectorList(igraph_vector_ptr_t * vl, FILE *f) {
      long int i,n;
      n = igraph_vector_ptr_size(vl);
      for (i=0; i<n; i++) {
        igraph_vector_t * vt;
        vt=(igraph_vector_t*)igraph_vector_ptr_e(vl,i);
        print_vector((igraph_vector_t*)vt,f);
        igraph_vector_destroy(vt);
        free(vt);
      }
}

long int GetElementVectorList(igraph_vector_ptr_t vl,long int i,long int j) {

         igraph_vector_t * vt;
         vt=(igraph_vector_t*)igraph_vector_ptr_e(&vl,i);
         return(VECTOR(*(igraph_vector_t*)vt)[j]);

}

int main() {

  igraph_t g;
  igraph_vector_t v;

  igraph_vector_init(&v,32);
  VECTOR(v)[0]=0; VECTOR(v)[1]=1;
  VECTOR(v)[2]=0; VECTOR(v)[3]=4;
  VECTOR(v)[4]=0; VECTOR(v)[5]=9;
  VECTOR(v)[6]=1; VECTOR(v)[7]=7;
  VECTOR(v)[8]=1; VECTOR(v)[9]=9;
  VECTOR(v)[10]=2; VECTOR(v)[11]=9;
  VECTOR(v)[12]=2; VECTOR(v)[13]=3;
  VECTOR(v)[14]=2; VECTOR(v)[15]=5;
  VECTOR(v)[16]=3; VECTOR(v)[17]=6;
  VECTOR(v)[18]=3; VECTOR(v)[19]=9;
  VECTOR(v)[20]=4; VECTOR(v)[21]=5;
  VECTOR(v)[22]=4; VECTOR(v)[23]=8;
  VECTOR(v)[24]=5; VECTOR(v)[25]=8;
  VECTOR(v)[26]=6; VECTOR(v)[27]=7;
  VECTOR(v)[28]=6; VECTOR(v)[29]=8;
  VECTOR(v)[30]=7; VECTOR(v)[31]=8;

  igraph_create(&g, &v, 0,0);


  // Neighbors

    igraph_vector_ptr_t vn1;
    igraph_vs_t vs;

   igraph_vector_ptr_init(&vn1, 0);
   igraph_vs_vector_small(&vs, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
   igraph_neighborhood(&g, &vn1,vs, 1, IGRAPH_OUT);

   print_vectorList(&vn1, stdout);  // **comment here and.....**


   igraph_vector_t v2;
   igraph_vector_init(&v2,2);
   VECTOR(v2)[0]=GetElementVectorList(vn1,6,1); VECTOR(v2)[1]=GetElementVectorList(vn1,6,2);

   cout<<VECTOR(v2)[0]<<endl;        // **you can get a good result here**
   cout<<VECTOR(v2)[1]<<endl;


  igraph_destroy(&g);
  igraph_vector_destroy(&v);
  igraph_vector_ptr_destroy_all(&vn1);
  igraph_vs_destroy(&vs);
  igraph_vector_destroy(&v2);

  return 0;
}

It seem that something happen with the function print but i don’t know what what happened.

Thanks in advance

vacing

  • 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-02T13:03:59+00:00Added an answer on June 2, 2026 at 1:03 pm

    You are destroying the vector in print_vectorList — no wonder you don’t see its contents afterwards when you try to print it from main.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.