Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following code may be useful:</p> <pre><code>int t1,t2; double t3;//global variables... void parse_Vertex_Line(char *str) { int tmp=0; char *p=str; //extract the vertex-id while(*p &gt;='0' &amp;&amp; *p &lt;='9') tmp = tmp*10 + *(p++) -'0'; t1=tmp; tmp=0; p++; //now extract the vertex-name.. while(*p &gt;='0' &amp;&amp; *p &lt;='9') tmp = tmp*10 + *(p++) -'0'; t2=tmp; return; } void parse_Edge_Line(char *str) { //extracting the first two numbers is just the same... int tmp=0; char *p=str; //extract the first vertex-id while(*p &gt;='0' &amp;&amp; *p &lt;='9') tmp = tmp*10 + *(p++) -'0'; t1=tmp; tmp=0; p++; //now extract the second vertex-id.. while(*p &gt;='0' &amp;&amp; *p &lt;='9') tmp = tmp*10 + *(p++) -'0'; t2=tmp; p++; //but extracting a double value is a bit different... //extract the weight... int before_decimal=0, after_decimal=0; while(*p!='.') before_decimal = before_decimal*10 + *(p++) -'0'; p++; int no_of_digits=0; while(*p&gt;='0' &amp;&amp; *p&lt;='9') { after_decimal = after_decimal*10 + *(p++) -'0'; no_of_digits++; } //assign it to the global double variable... t3 = before_decimal + (after_decimal/pow(10.0, no_of_digits)); } </code></pre> <p>Now what you do is first get the <code>number of vertices(n)</code>. Next read each of the <code>n</code> lines. Calling the function <code>parse_Vertex_Line</code> each time. Then read the <code>number of edges</code> and similarly call <code>parse_Edge_Line</code> each time. Extract the values and Store them.</p> <p>This code works for almost any delimiters. Hope this looks elegant to you. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload