Thank you guys, for your quick answer! Tamas: I understand what you say. I tried exactly the same casting you suggested me, but unfortunately nothing changed. In attach I am sending the source file (as I said, it is the same "foreign.c" that is in the igraph manual).
Gábor: I am sending also the output of the ldd foreign, the commands I use to compile it, the way I run it (./foreign), and the output I got when I run it. I hope it helps us to understand what it is happening. I was wondering if it may be an error because I am compiling the igraph in my home, and so because of it I am doing something wrong when I am linking the libraries during the compilation. Thank you for your attention, Best, Charles On Mon, Dec 10, 2012 at 10:45 AM, Tamás Nepusz <[email protected]> wrote: > Dear Charles, > >> number of vertices of a network from in simple pajek file. The program >> compiles correctly, it reads the edges of the network correctly, but >> it reads the number of vertices like a strange number, like -10585152. > I'm 99% sure that this is a printing/formatting issue, i.e. the number in the > variable is fine but you print it with the wrong format string. The reason > why it happens on a 64-bit machine only is because the variable type that > printf expects for that particular format string that you are using happens > to be of the same length as your actual variable on a 32-bit machine but not > on a 64-bit machine. > > For the record, igraph_vcount returns the vertex count in an > igraph_integer_t. _Internally_, igraph_integer_t used to be a double before > igraph 0.6, but that confused the hell out of people (including me) so we > switched to igraph_integer_t being a long int. That being said, the safest > way to print an igraph_integer_t is by casting it explicitly to a long int to > make sure that the code works with every igraph version: > > igraph_integer_t whatever; > [...] > printf("whatever = %ld\n", (long int)whatever); > > Best, > Tamas > > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help -- Um axé! :) -- Charles Novaes de Santana http://www.imedea.uib-csic.es/~charles PhD student - Global Change Laboratorio Internacional de Cambio Global Department of Global Change Research Instituto Mediterráneo de Estudios Avanzados(CSIC/UIB) Calle Miquel Marques 21, 07190 Esporles - Islas Baleares - España Office phone - +34 971 610 896 Cell phone - +34 660 207 940
run_foreign.sh
Description: Bourne shell script
output_foreign.dat
Description: Binary data
ldd_foreign.dat
Description: Binary data
#include <igraph.h>
#include <stdio.h>
int main(int argc, char **argv) {
igraph_t g;
FILE *ifile;
/* PAJEK */
ifile=fopen("LINKS.NET", "r");
if (ifile==0) {
return 10;
}
igraph_read_graph_pajek(&g, ifile);
fclose(ifile);
printf("The graph:\n");
printf("Vertices = %ld\n", (long int) igraph_vcount(&g));
printf("Vertices: %li\n", (long int) igraph_vcount(&g));
printf("Edges: %li\n", (long int) igraph_ecount(&g));
printf("Directed: %i\n", (int) igraph_is_directed(&g));
igraph_write_graph_edgelist(&g, stdout);
igraph_destroy(&g);
return 0;
}
compile_foreign.sh
Description: Bourne shell script
LINKS.NET
Description: Binary data
_______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
