/* zzz.c */
/* testing subprogram NOWTS */
#include <stdio.h>
#define NN 500
int NOWTS(char*,int*,int*);

void main(void)
{
 char AARY[] = "1,2,3,  2,3,4,  3,4,  4,  0,0";
 int I,N,TAIL[NN],HEAD[NN];

 N=NOWTS(AARY,TAIL,HEAD);
 printf("%d edges or arcs including pseudo-edges or pseudo-arcs\n",N);
 for (I=0; I<N; I++) printf("%d-%d  ",TAIL[I],HEAD[I]);
 getchar();
}

/********************/

/* Converting an adjacency array WITHOUT weights to TAIL,HEAD arrays */
int NOWTS(char *P, int *TAIL, int *HEAD)
{
 int I=0,K,TEMP,CNT;

NEWCL:  /* start new (next) cluster;  process leading integer */
 while (*P<'0' || *P>'9') P++;   
 TEMP=0; while (*P>='0' &&  *P<='9') {TEMP = 10*TEMP +(int)*P - 48; P++;}
 K=TEMP;  CNT=0;

SECINT:  /* process secondary integer, if any */
 while (*P>'9' || (*P<'0' && *P!=' ')) P++;
 if (*P==' ')
  {
   if (!CNT) {TAIL[I]=K; HEAD[I]=0; I++;}    /* no secondary ints in cluster */
   goto NEWCL;
  }
 TEMP=0; while (*P>='0' &&  *P<='9') {TEMP = 10*TEMP +(int)*P - 48; P++;}
 TAIL[I]=K; HEAD[I]=TEMP;  CNT++;
 if (TEMP || K) {I++; goto SECINT;}
 return I;
}

