Ejemplo n.º 1
0
int main ()
{
	testResult_t *result = initializeTestResult();

	getFS();	

	deleteFile("File to Delete");
	deleteDir("Dir to Delete");

	int newFd = openFile("NewFile");

	char *text = "Here is some text.";
	int writeLen = writeInFile(newFd, text, strlen(text));
	assert(writeLen == strlen(text), "File write return value test.", result);
	seekInFile(newFd, 0);
	char target[100];
	memset(target, 0, sizeof(target));
	int readLen = readInFile(newFd, target, strlen(text));
	assert(readLen == strlen(text), "File write return value test.", result);
	deny(strcmp(target, text), "Read + write test.", result);

	int fd = openFile("File to Delete");

	seekInFile(newFd, FILE_BLOCK_DATA_SIZE - 2);
	writeLen = writeInFile(newFd, text, strlen(text));
	seekInFile(newFd, FILE_BLOCK_DATA_SIZE - 2);
	readLen = readInFile(newFd, target, strlen(text));
	assert(readLen == strlen(text), "Non-contiguous allocation read+write test.", result);
	deny(strcmp(target, text), "Read + write test.", result);

	mkDir("Dir to Delete");

	giveDirListing();

	deleteFile("File to Delete");
	mkDir("NewDir");
	giveDirListing();

	deleteDir("Dir to Delete");

	giveDirListing();

	seekInFile(newFd, 0);

	int i;
	for (i = 0; i < 150; i++)
	{
		writeInFile(newFd, text, strlen(text));
		seekInFile(newFd, (i * FILE_BLOCK_DATA_SIZE) - 2);
	}

	printTestResult(result);
	freeTestResult(result);
	return 0;
}
Ejemplo n.º 2
0
int main (int argc, char* argv []) {
    int nbOcc;
    nbOcc = 0;
    
    if (argc < 3 ) {
        printf("Erreur arg");
        return 0;
    }
    
    memcpy (buff_path,argv[2],strlen(argv[2]));
    
    if ( ( pt_Dir = opendir (buff_path) ) == NULL) {
        perror("Repertoire");
        return 0;
    }
    
    /* lire répertoire */
    while ((dirEnt= readdir (pt_Dir)) != NULL) {
        strcpy(tmp,buff_path);
        
        strcat(tmp,"/");
        strcat(tmp,dirEnt->d_name);
        
        nbOcc += readInFile(tmp,argv[1]);
        memset(tmp, '\0', sizeof(tmp));
    }
    
    if(nbOcc == 0)
        printf("Aucun fichier valide\n");
    
    closedir (pt_Dir);
    
    return 0;
}
Ejemplo n.º 3
0
void stage1( char* X_name, int r, int c )       //r is row index, c is column index
{
   matrix *mainMatrix;
   mainMatrix = readInFile(X_name);
   //find the value in r,c
   int value;
   value = findingValue(c, r, mainMatrix);
   printf("%d\n", value);                          //prints the value
   printRow(mainMatrix, r);
   printCol(mainMatrix, c);
   return;
}
int main(int argc, char **argv) {
	if (argc < 2) {
		printf("\nInput file needed. Exiting...\n");
		return 0;
	}

	FILE *input = fopen(argv[1], "r");
	char pt, c;
	int i = 0, numChars, shifts[3] = {0};
   	float charCount[26] = {0};
	table *alphabet = NULL;
	
	alphabet = readInFile(alphabet, "letterFrequencies.txt");
	
	numChars = countFrequency(input, charCount);
	computeFrequency(numChars, charCount);

	printf("\nFREQUENCY ANALYSIS ATTACK ON THE SHIFT CIPHER"
			"\n--------------------------------------");

	table *inputFrequencies = NULL;
	
	int a = 0;
	while (a < 26) {
		inputFrequencies = loadTable(inputFrequencies, a+97, charCount[a], 0);
		a++;
	}
	
	pickTopShifts(inputFrequencies, shifts);
	table *temp = inputFrequencies;

	printf("\nTESTING TOP 3 SHIFT POSSIBILITIES\n");
	for (i = 0; i < 3; i++) {
		rewind(input);
		printf("\nDecryption %d/3; Shift :%d\t", i+1, shifts[i]-4);
		while((c = getc(input)) != EOF){
			pt = decrypt(c, shifts[i]-4);
			putchar(pt);
		}
	}

	printf("\n");
	fclose(input);
	return 0;
}
Ejemplo n.º 5
0
BookTracker::BookTracker(void)
{
    head = nullptr;
    readInFile();
}
Ejemplo n.º 6
0
int main(void)
{

  printf("========= Starts Numerics tests for NumericsMatrix ========= \n");

  int i, nmm = 4 ;
  NumericsMatrix ** NMM = (NumericsMatrix **)malloc(nmm * sizeof(NumericsMatrix *)) ;
  NumericsMatrix ** Mread = (NumericsMatrix **)malloc(nmm * sizeof(NumericsMatrix *)) ;


  for (i = 0 ; i < nmm; i++)
  {
    NMM[i] = newNumericsMatrix();
    Mread[i] = newNumericsMatrix();
  }


  int info = test_BuildNumericsMatrix(NMM);

  if (info != 0)
  {
    printf("Construction failed ...\n");
    return info;
  }
  printf("Construction ok ...\n");

  /* Test of various I/O functions */

  for (i = 0 ; i < nmm; i++)
  {

    printf("test on NMM[%i]\n", i);

    NM_display(NMM[i]);
    displayRowbyRow(NMM[i]);
    FILE * foutput = fopen("testprintInfile.dat", "w");
    printInFile(NMM[i], foutput);
    fclose(foutput);
    FILE * finput = fopen("testprintInfile.dat", "r");
    readInFile(NMM[i], finput);
    fclose(finput);
    FILE * finput2 = fopen("testprintInfile.dat", "r");
    newFromFile(Mread[i], finput2);
    fclose(finput2);
    char  filename[50] = "testprintInfileName.dat";
    printInFileName(NMM[i], filename);
    readInFileName(NMM[i], filename);
    printf("end of test on NMM[%i]\n", i);

  }
  for (i = 0 ; i < nmm; i++, i++)
  {
    FILE * foutput2 = fopen("testprintInfileForScilab.dat", "w");
    printInFileForScilab(NMM[i], foutput2);
    fclose(foutput2);
  }



  /* free memory */

  for (i = 0 ; i < nmm; i++)
  {
    freeNumericsMatrix(NMM[i]);
    free(NMM[i]);
    freeNumericsMatrix(Mread[i]);
    free(Mread[i]);
  }

  free(NMM);
  free(Mread);



  printf("========= End Numerics tests for NumericsMatrix ========= \n");
  return info;
}
Ejemplo n.º 7
0
womackscStarbucks::womackscStarbucks(string data){
		readInFile(data);
}