示例#1
0
int main  ( int argc, char **argv ) {
#ifdef DEBUG
	printf("IN MAIN\n");
#endif
	/*Displays Help Command*/
	if(argc!=MIN_REQUIRED || !strcmp(argv[1], "-h")) {
		return help();
	}
	double time_spent;
	char* stringFile = readFile(argv[1]);
	if(stringFile == NULL){
		return help();
	}
	int numberWords=countCharacters(stringFile, ' ', '\n', '\t');
#ifdef DEBUG
	printf("File: %s\nTotal number of Words: %d\n %s\n",argv[1], numberWords, stringFile);
#endif
	clock_t tic = clock();
	parseText(stringFile, numberWords);
	clock_t toc = clock();
	printList();
	time_spent=(double)(toc-tic)/CLOCKS_PER_SEC;
	time_spent=time_spent/1000000;
#ifdef DEBUG
	printf("\n =========\n TIME SPENT: %.032f \n =========\n", time_spent);
#endif
#ifdef DEBUG
	printf("OUT OF MAIN\n");
#endif
	freeList();
	free(stringFile);
	return 0;
  }
void populateDataStructuresFromString(std::string &line) {
  std::transform(line.begin(), line.end(), line.begin(), ::tolower); 
  std::map<char, int> letterCounts = countCharacters(line);
  std::map<char, int>::iterator it;
  std::multimap<int, char> flippedMap;
  for (it = letterCounts.begin(); it != letterCounts.end(); ++it) {
    flippedMap.insert(std::pair<int, char>(it->second, it->first));
  }
  printMaximumBeautySum(flippedMap);
}
示例#3
0
int main(int argc, char const *argv[])
{
	if (argc != 4)
	{
		printf("incorrect number of parameters\n");
		return 0;
	}

	if (strlen(argv[3]) != 1)
	{
		printf("invalid parameter <%s>, must be a char\n",argv[3]);
		return 0;
	}

	//get parameters
	const char* _path = argv[2];
	char _input = argv[3][0];
	int _nChar = 0;

	//open file
	int _fd = open(_path,O_RDONLY);
	if (_fd == -1)
	{
		printf("File doesn't exists or is unaccesible\n");
		return 0;
	}

	//parse mode
	if (strcmp(argv[1],"R") == 0) // call to readchar in a loop
	{
		int i;
		int _fileSize = lseek(_fd,0,SEEK_END);
		for (i=0; i < _fileSize; ++i)
		{
			if (readCharacter(_fd,i) == _input)
				_nChar++;
		}
	}else if (strcmp(argv[1],"M") == 0)//call to countM
	{
		_nChar = countCharacters(_fd,_input);
	}else
	{
		printf("Parameter <%s> unknown\n",argv[1]);
		return 0;
	}

	printf("%d\n",_nChar);

	if (close(_fd)!=0)
		perror("Problem closing file");

	return 0;
}
示例#4
0
void String::append(const char* szBegin, size_t nBytes, int bClear)
{
  // Do not copy onto itself, but allow apppend to self
  if (szStr_ == szBegin && bClear) { return; }

  if (bClear) {
    clear();
  }

  if (szBegin != 0 && nBytes > 0) {
    size_t nLen1InChars = nChars_;
    size_t nLen2InChars = countCharacters(szBegin, nBytes);
    size_t nLen1InBytes = nBytes_;
    size_t nLen2InBytes = nBytes;
    size_t nLenInBytes = nLen1InBytes + nLen2InBytes;

    if (nLen2InChars > 0 && nLen2InBytes > 0) {

      if (nAllocated_ > nLenInBytes) { // ">" because of the 0
        ::memcpy(szStr_ + nLen1InBytes, szBegin, nLen2InBytes);
        szStr_[nLen1InBytes + nLen2InBytes] = '\0';

      } else {

        size_t nAllocate = (nLenInBytes > nAllocated_) ? 2 * nLenInBytes : 2 * nAllocated_;
        nAllocate = (nAllocate < 64 ? 64 : nAllocate);

        char* szTmp = (char*) SSystem::malloc(nAllocate);
        if (szTmp == 0) {
          return; // no change due to mem alloc problem
        }

        nAllocated_ = nAllocate;
        if (szStr_ != 0) {
          memcpy(szTmp, szStr_, nLen1InBytes);
        }
        memcpy(szTmp + nLen1InBytes, szBegin, nLen2InBytes);
        szTmp[nLen1InBytes + nLen2InBytes] = '\0';

        if (szStr_ != 0) { SSystem::free(szStr_); }
        szStr_ = szTmp;
      }

      nBytes_ = nLen1InBytes + nLen2InBytes;
      nChars_ = nLen1InChars + nLen2InChars;
    }
  }
}
示例#5
0
int main  ( int argc, char **argv ) {
	/*Displays Help Command*/
	if(argc!=2 || !strcmp(argv[1], "-h")) {
		return help();
	}
	clock_t tic = clock();
	double time_spent;
	char* stringFile = readFile(argv[1]);
	int numberWords=countCharacters(stringFile, ' ', '\n', '\t'), i;
	printf("File: %s\nTotal number of Words: %d\n %s\n",argv[1], numberWords, stringFile);
	printf("%d\n", hash("bob", 100)% 100);
	parseText(stringFile, numberWords);
	clock_t toc = clock();
	time_spent=(double)(toc-tic)/CLOCKS_PER_SEC;
	time_spent=time_spent/1000000;
	printf("\n =========\n TIME SPENT: %.06f \n =========\n", time_spent);
	return 0;
}