int main(void) { FILE *pf; char name[20]; int TIME[15]; int time, money; int sum_time, sum_money; int t; // number of elements of array TIME int i,readt; pf = fopen("store.txt", "r"); if (pf == NULL) { perror("Cannot open file"); return (-1); } sum_time = 0; sum_money = 0; t = 0; while (fscanf(pf, "%d", &readt) > 0) { TIME[t] = readt; t++; } while (fscanf(pf, "%s %d %d", name, &money, &time) > 0) { Enque(money, time, name); } i=0; while (i < t) { NodeT *elem; elem = head; sum_time = 0; sum_money = 0; while (elem != NULL) { if ((sum_time + elem->time) <= TIME[i]) { sum_time = sum_time + elem->time; sum_money = sum_money + elem->money; } elem=elem->next; } printf("After %d seconds: %d and total amount of time %d\n", TIME[i], sum_money, sum_time); i++; } PrintList(); fclose(pf); return(0); }
int Send_Message(int* Data, int Length) { if ((Remaining_Space() == 0) || (Remaining_Space() > Length)) { while (Length) { int Check = Enque(*Data); if (Check == -2) { break; } Data++; Length--; } if (Length != 0) { return -2; } else if (Length == 0) { /*If the Buffer is not empty and do not disturb is false*/ if (RingBuffer.Head != -1 && RingBuffer.DND == false) { /*Chek whether Tail is greater than the head therefore there is no rollover for the buffer*/ while (RingBuffer.Head == -1) /*until the buffer is empty call the senddata function*/ { RingBuffer.Send_Done = false; Send_Data((RingBuffer.Buffer + RingBuffer.Head), SENDSIZE); while (RingBuffer.Send_Done == false) { /*Wait till the data has been properly sent*/ } } return 0; } return 0; } } else { return -2; } }
int main( void ){ IntQueue que; if( Initialize( &que, 10 ) == -1 ){ puts( "キューの生成に失敗しました。" ); return -1; } while( 1 ){ int m, x; printf( "現在のデータ数:%d / %d\n", Size( &que ), Capacity( &que ) ); printf( "(1)エンキュー (2)デキュー (3)ピーク (4)表示 (0)終了 :" ); scanf( "%d", &m ); if( m == 0 ) break; switch( m ){ case 1: //Enque printf("データ:"); scanf( "%d", &x ); if( Enque( &que, x ) == -1 ) puts( "\aエラー:データのエンキューに失敗しました。" ); break; case 2: //Deque if( Deque( &que, &x ) == -1 ) puts( "\aエラー:デキューに失敗しました。" ); else printf( "デキューしたデータは%dです。\n", x ); break; case 3: //Peek if( Peek( &que, &x ) == -1 ) puts( "ピークに失敗しました。" ); else printf( "ピークしたデータは%dです。\n, x" ); break; case 4: Print( &que ); break; } } Terminate( &que ); return 0; }
int main() { FILE *IN,*OUT; IN=fopen("input.dat","r"); OUT=fopen("output.dat","w"); int x[100],i=0,j,sumtime=0,summoney=0,timex,moneyx,g=1; char a[100],*money,*time,r[100]; while(!feof(IN)) { fscanf(IN,"%s",r); if(r[0]<'0' || r[0]>'9') break; x[i]=atoi(r); i++; } while(fgets(a,100,IN)) { if(g==1) { money=strtok(a," "); time=strtok(NULL," \n"); g++; } else { strtok(a," \n"); money=strtok(NULL," "); time=strtok(NULL," "); } Enque(atoi(time),atoi(money)); } for(j=0; j<i; j++) { peek(timex,moneyx); sum(moneyx,timex,sumtime,summoney); Deque(); if(sumtime>x[j]) fprintf(OUT,"After %d seconds: %d\n",x[j],summoney-timex); else fprintf(OUT,"After %d seconds: %d\n",x[j],summoney); } return 0; }
int SendMessage(int* Data, int Length, Endo_Callback callback) { if ((Length + SpaceUsed()) <= MAXSIZE) { while (Length) { int Check = Enque(*Data); if (Check == -2) { break; } Data++; Length--; } if (Length != 0) { return -2; } else if (Length == 0) { if (!isbusy()) { ApiMakeEmpty(); callback(); return 0; } return 0; } } else { return -2; } return -2; }