Conversion of adjacency list to adjacency matrix using c language

622 views
Skip to first unread message

AJ

unread,
Feb 24, 2013, 3:04:24 AM2/24/13
to pu...@googlegroups.com
hey

i want to convert adjacency list to adjacency matrix .Used all function like getline() ,getdelim() ,getc() and gets but don't get the answer. i am attaching an input file and source code file . i am using terminal as compiler. Anyone knows how to use combination of getline() and getdelim()? if anyone knows an efficient method than this, please reply.

with regards
aj
myfile.txt
sourcecode.c

Ankit Bhatnagar

unread,
Feb 24, 2013, 10:07:19 AM2/24/13
to pu...@googlegroups.com
Hi Ajay,

You can try the following method, which uses a char buffer to read the input file and then extracts integers accordingly.

Check my code here : http://pastebin.com/vtEyRFEg

If you face any problems understanding it, feel free to post your query! 


aj

--
You received this message because you are subscribed to the Google Groups "PULUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulug+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Wishes.
Ankit.

Ankit Bhatnagar

unread,
Feb 24, 2013, 10:12:19 AM2/24/13
to pu...@googlegroups.com
Sorry for a typo,

On line 16, it should be this :-
  1. if(buffer[i]=='\n' || buffer[i]==' ')
  2. {

    }                


This is to include space seperation as well. The earlier logic works for single integer on every line.
--
Wishes.
Ankit.

Ajay Kumar

unread,
Feb 24, 2013, 9:01:47 PM2/24/13
to pu...@googlegroups.com
hey
i solved  problem by initializing all array integer with 0.thanks for ur help

with regards
ajay


happy singh

unread,
Feb 25, 2013, 12:49:23 AM2/25/13
to pu...@googlegroups.com
hey,

Use "memset" to initialize your array to all zeros. Here is a example :

memset(array, 0, sizeof(array[0][0]) * m * n);

where m and n are number of rows and number of columns respectively.

See 1 line of code..






Reply all
Reply to author
Forward
0 new messages