예제 #1
0
파일: call_numsort.c 프로젝트: BeMg/ARM
int main(){
    int a[10];
    int i,j;
    int *result;
    char output[100];
    for(i=0,j=9; i<9; i++,j--){
            a[i] = j;
    }
    a[1] = 1;
    a[2] = 1;
    a[5] = 7;
    a[8] = 2;
    for(i=0; i<9; i++)
        printf("%d%c",a[i],i==8 ? '\n' : ' ');
    result = NumSort(9,a);
    int cnt = 0;
    for(i=0; i<9; i++){
        output[cnt++] = result[i]+'0';
        if(i==8)
            output[cnt++] = '\n';
        else
            output[cnt++] = ' ';
    }
    FileOutput(output);
    return 0;
}
예제 #2
0
    void ProcessData(const T *Values,
                     typename ValueArray::size_type Size,
                     FnWriter pfnWriter,
                     FnReader pfnReader)
    {
        ValueArray InValues(Size);

        {
            wxFileOutputStream FileOutput( wxT("mytext.dat") );
            wxDataOutputStream DataOutput( FileOutput );

            (DataOutput.*pfnWriter)(Values, Size);
        }

        {
            wxFileInputStream FileInput( wxT("mytext.dat") );
            wxDataInputStream DataInput( FileInput );

            (DataInput.*pfnReader)(&*InValues.begin(), InValues.size());
        }

        m_ok = true;
        for (typename ValueArray::size_type idx=0; idx!=Size; ++idx) {
            if (InValues[idx]!=Values[idx]) {
                m_ok = false;
                break;
            }
        }
    }
예제 #3
0
    std::unique_ptr<OutputStream> getOutputStream(const Zstring& itemPathImpl,  //throw FileError, ErrorTargetExisting
                                                  const std::uint64_t* streamSize,                     //optional
                                                  const std::int64_t* modificationTime) const override //
    {
        initComForThread(); //throw FileError

        //AbstractBaseFolder::OutputStream takes ownership and deletes on errors!!!! => transactionally create output stream first!!
        auto&& fop = FileOutput(itemPathImpl, FileOutput::ACC_CREATE_NEW); //throw FileError, ErrorTargetExisting
        return std::make_unique<OutputStreamNative>(std::move(fop), makeAbstractItem(*this, itemPathImpl), streamSize, modificationTime); //throw FileError
    }
예제 #4
0
int  SaveConfigFile( TidyDocImpl* doc, ctmbstr cfgfil )
{
    int status = -1;
    StreamOut* out = NULL;
    uint outenc = cfg( doc, TidyOutCharEncoding );
    uint nl = cfg( doc, TidyNewline );
    FILE* fout = fopen( cfgfil, "wb" );
    if ( fout )
    {
        out = FileOutput( fout, outenc, nl );
        status = SaveConfigToStream( doc, out );
        fclose( fout );
        MemFree( out );
    }
    return status;
}
예제 #5
0
static
T TestRW(const T &Value)
{
    T InValue;

    {
        wxFileOutputStream FileOutput( wxT("mytext.dat") );
        wxDataOutputStream DataOutput( FileOutput );

        DataOutput << Value;
    }

    {
        wxFileInputStream FileInput( wxT("mytext.dat") );
        wxDataInputStream DataInput( FileInput );

        DataInput >> InValue;
    }

    return InValue;
}
예제 #6
0
void BLIFwriter::annotate(const string& msg){
	Dout( cout<<msg );
	FileOutput(output<<msg<<endl);
}
예제 #7
0
int main (void)
{
	int answer;

	CreatorInfo();

	while (true)
		{
			printf("================== MENU ==================\n");
			printf("1. Input the database;\n");
			printf("2. Supplement to the database;\n");
			printf("3. Edit the database;\n");
			printf("4. Delete the element in the database;\n");
			printf("5. Output the database;\n");
			printf("6. Output the worst students list;\n");
			printf("7. Output the teachers-docents list;\n");
			printf("8. Output the totall budget of faculties;\n");
			printf("0. Exit.\n\n");

			scanf("%d", &answer);

			switch (answer)
				{
					case INPUT:
						{
							FileInit();
							break;
						}
					case SUPPLEMENT:
						{
							FileSupplement();
							break;
						}
					case EDIT:
						{
							FileEditing();
							break;
						}
					case DELETE:
						{
							FileDelete();
							break;
						}
					case OUTPUT:
						{
							FileOutput();
							break;
						}
					case VIEWSTUD:
						{
							LowestScore();
							break;
						}
					case VIEWTEACH:
						{
							Docents();
							break;
						}
					case BUDGET:
						{
							TotallBudget();
							break;
						}
					case EXIT:
						{
							exit (false);
							break;
						}
					default:
						printf("Something went wrong...\n");
				}
		}
}
void Sync_Send(std::string File, std::string Message) {
    std::ofstream FileOutput (File);
    FileOutput << Message;
    FileOutput.close();
}
// ----------------------------------------------------------------------------
// MAINLINE LOGIC
// ----------------------------------------------------------------------------
int main() {
	
	// declarations
	int  action = UNSET;
	char rawPT[BUFFER_SIZE]    = "";
	char cleanPT[BUFFER_SIZE]  = "";
	int  a = A, b = B, inverse = INVERSE, n = ALPHABET_SIZE;
	char nameInputFile[30]     = "input.txt" ;
	char nameOutputFile[30]    = "output.txt";

	// seed the random number generator
	srand((unsigned int)time(NULL));

	// get ready
	action = fGetClnStr(action, rawPT, cleanPT);
	
	// display title page
	DispHeader(nameInputFile, nameOutputFile, a, b, inverse);
	puts("Welcome to Derrida - the command line Affine Cipher!");
	Pause();

	// detail loop
	while(action != QUIT) {
		ClearScreen();

		DispHeader(nameInputFile, nameOutputFile, a, b, inverse);
		
		// select an action
		action = SelectAction(action);
		
		DispHeader(nameInputFile, nameOutputFile, a, b, inverse);

		// execute action
		switch(action) {
		case SET_I_FILE: // change the input file
			action = fGetClnStr(action, rawPT, cleanPT, nameInputFile);
			break;
		case SET_O_FILE: // change the output file
			action = SetOutputFileName(nameOutputFile);
			break;
		case DIR_LIST: // display directory listing
			list_dir();
			break;
		case SET_KEY: // change cipher key
			action = SetCipherKey(a, b, n, inverse);
			break;
		case ENCRYPT: // encrypt the PT codes

			// display the string before encryption
			printf("Before encryption, the string contains:\n");
			puts(rawPT);
			printf("\n");
			printf("Sanatized, the string contains:\n");
			puts(cleanPT);
			printf("\n");
			// if encryption succeeds, inform the user
			if(EncryptString(cleanPT, a, b, n)) {
				FileOutput(nameOutputFile, cleanPT);
				printf("After encryption, the string contains:\n");
				puts(cleanPT);
				printf("\n");
			}

			Pause();
			break;

		case DECRYPT:
			// display the clean cipher code before decryption
			puts("Before decryption, the string contains:");
			puts(cleanPT);
			puts("\n");
			// if decryption succeeds, inform the user
			if(DecryptString(cleanPT, a, b, n)) {
				FileOutput(nameOutputFile, cleanPT);
				puts("After decryption, the string contains:\n");
				puts(cleanPT);
				puts("\n");
			}

			Pause();
			break;	
		}		
	}

	puts("The program will now exit.");
	Pause();

	// exit program
	return 0;
}
예제 #10
0
int main(){

  PARTICLE *p,*pn;
  p=malloc(sizeof(PARTICLE)); //need to allocate memory to pointer
  pn=malloc(sizeof(PARTICLE));
  FILE *fp;

	double dDelta,t,tmax;
  double CnPreFac, CtPreFac, dLnEpsN, dLnEpsT, dLnEpsNsq, dLnEpsTsq, a;;
  int i;
  int nSteps,iStep=0;
  int iOutFreq;
  int bOverlap=0;
  char achOutFile[20];

  //Need to initialize dKn for each particle
  p->dKn = 1.06e-15;
  p->dKt = 2.*p->dKn/7.;
  p->dEpsN = 0.8;
  p->dEpsT = 0.8;
  p->dMuS = 0.4;
  
  pn->dKn = p->dKn;
  pn->dKt = p->dKt;
  pn->dEpsN = p->dEpsN;
  pn->dEpsT = p->dEpsT;
  pn->dMuS = p->dMuS;
  
  dDelta=1.47e-10;
  nSteps = 40000;
  iOutFreq = nSteps / 50;
  t=0;
  tmax=dDelta * nSteps;
 
 
  const double pi_sq = M_PI*M_PI;
  static int bCnCtPreFacCalculated = 0; /* since dEpsN and dEpsT are identical for all particles in sim */

  if (!bCnCtPreFacCalculated) {
    /* damping term: normal */
    dLnEpsN = log(p->dEpsN);
    dLnEpsNsq = dLnEpsN*dLnEpsN;
    a = pi_sq + dLnEpsNsq;
    CnPreFac = -sign(dLnEpsN)*sqrt(dLnEpsNsq*p->dKn/a);
    CnPreFac += CnPreFac;

    /* damping term: tangential */
    dLnEpsT = log(p->dEpsT);
    dLnEpsTsq = dLnEpsT*dLnEpsT;
    a = pi_sq + dLnEpsTsq;
    CtPreFac = -sign(dLnEpsT)*sqrt(dLnEpsTsq*p->dKt/a);
    CtPreFac += CtPreFac;
    bCnCtPreFacCalculated = 1;
    }

  /*Take input from FILE here - Initialization*/
  FileInput(p, pn);

  
  /*Simulation loop here*/
  while (t<tmax){
  
    /* Output to file Here*/
    if ((t == 0) || (iStep % iOutFreq == 0)){
      /*Define File Name based on time step*/
      sprintf(achOutFile,"ss.%09d.bt",iStep);
      /*Output function*/
		  FileOutput(p, pn, achOutFile);
    }
    /* Output-Function Ends Here*/
    

    /* LeapFrog */
    for (i=0;i<3;i++){
      p->v[i]=p->v[i]+(0.5*dDelta*p->a[i]); //kick
      pn->v[i]=pn->v[i]+(0.5*dDelta*pn->a[i]);
    }

    for (i=0;i<3;i++){
  	  p->r[i]=p->r[i]+(dDelta*p->v[i]); //drift
  	  pn->r[i]=pn->r[i]+(dDelta*pn->v[i]); //
    }

    //Overlap Test
        bOverlap = bOverlapTest(p,pn);
    if (bOverlap){
      DoDEM(p, pn, dDelta, CnPreFac, CtPreFac);
      printf("%d\n",bOverlap);
    }
    else{
      vecZero(p->a); //Is this correct?
      vecZero(pn->a);
    }
    
    for (i=0;i<3;i++){
      p->v[i]=p->v[i]+(0.5*dDelta*p->a[i]); //kick
      pn->v[i]=pn->v[i]+(0.5*dDelta*pn->a[i]);
    }
    /* LeapFrog ENDS*/


    t+=dDelta;
    iStep++;
  }
  
  return 0;
}