/* * read a line from the file and print it out with 'id' * which should identify which partner this is */ void readline(pid_t id, FILE *file) { char *e = fgets(linebuf, MAX_LINE_SIZE, file); int i =0,k=0; while(linebuf[i]!='\n' && linebuf[i]!='\0') { i++; k++; if(/*isalpha(linebuf[i]) &&*/ lettertonumber(linebuf[i])>9){ printf("K ADD\n"); k++; } } /* * Allocate memory and copy line */ char * line = malloc((k)*sizeof(char)); line[0]='\0'; i=0; char * number=malloc(5*sizeof(char)); char * ch = malloc(2*sizeof(char)); ch[1]='\0'; while(linebuf[i]!='\n' && linebuf[i]!='\0') { if(isalpha(linebuf[i])) { sprintf(number,"%d",lettertonumber(linebuf[i])); strcat(line,number); } else { ch[0]=linebuf[i]; strcat(line,ch); } i++; } if(e == NULL) { printf("[%d] *** NO LINE ***\n", id); } else { printf("%s %d\n",line,id); //printf("length: %d\n",strlen(line)); fflush(stdout); } fflush(stdout); }
long htoi(char s[]) { int startsymbol,i,_t; long sum; sum = 0; if ((s[0] == '0') && (s[1] == 'x' || s[1] == 'X')) startsymbol = 2; else startsymbol = 0; for (i=startsymbol; i < strlen(s); ++i) { if ((_t = lettertonumber(s[i])) > 0 ) sum = sum*16 + _t; else return -1; } /* printf("%ld\n", sum); */ return sum; }