Esempio n. 1
0
int main(int argc, char const *argv[])
{
	FILE* pFile = fopen(argv[1], "rb" );
	int fileSize;
	char buf[LEN_LIMT];

	if (pFile == NULL)
	{
		fprintf(stderr, "no this file\n");
		exit(1);
	}

	// obtain file size
	fseek(pFile, 0, SEEK_END);
	fileSize = ftell(pFile);
	rewind(pFile);

	int wc, nlc, flen;
	char isFirst = 1;

	flen = fread(buf, 1 ,LEN_LIMT, pFile);
	if (flen > 0)
	{
		wordCount(buf, flen, &wc, &nlc, isFirst);
		isFirst = 0;
	}

	while(!feof(pFile)){
		flen = fread(buf, 1 ,LEN_LIMT, pFile);
		wordCount(buf, flen, &wc, &nlc, isFirst);
	}
	printf("%d %d %d\n", nlc, wc, fileSize);
	return 0;
}
Esempio n. 2
0
// method to load data for corpus and search files
void loadCorpusAndSearchFiles(strIntMap& corpMap, strIntMap& docMap,
                              std::string searchFile,
                              std::vector<std::string> fileList) {
    std::for_each(fileList.begin(), fileList.end(), [&](std::string currFile) {
            wordCount(corpMap, currFile);
        });
    wordCount(docMap, searchFile);
}
Esempio n. 3
0
int main(){
    char originalstr[] = "USA,Canada,Mexico,Bermuda,Grenada,Belize";
    char* string9 = malloc((strlen(originalstr)+1)*sizeof(char));
    string9 = strcpy(string9, originalstr);
    
    // need a copy because calls to strtok(through wordCount and splitStringIntoArray) destroy the original string
    
    const char* delimiter = ",";
    
    int ct = wordCount(string9, delimiter);
    
    assert(ct>0); // crashes the program if assertion is not true
    
    char* resultarr[ct]; // declares array of appropriate size
    
    string9 = strcpy(string9, originalstr);
    
    splitStringIntoArray(string9, resultarr, delimiter);
    
    printf("\nAnswer #9 is\n");
    for (int i = 0; i < ct; i++) {
        printf("Token %d is %s\n",i,resultarr[i]);
    }
    
    free(string9);
    
    return 0;
    
    
}
bool LshKBM::save(FILE *f, unsigned char ver) const
{
  unsigned int signature = 0xFAADBEEB;
  WRITE_VAR(signature);
  ver = mVer; // added mJfinal and mDtKBinMeans
  WRITE_VAR(ver);
  WRITE_VAR(type);
  WRITE_VAR(dims);
  WRITE_VAR(num_descriptors);
  WRITE_VAR(num_images);
  unsigned int word_count = wordCount(); // how many centroids?
  WRITE_VAR(word_count);
  WRITE_VAR(mJfinal);
  WRITE_VAR(mDtKBinMeans);
  WRITE_VAR(m_guid);
  uint32_t m=mLshKbmP.getM(),l=mLshKbmP.getL();
  WRITE_VAR(m);
  WRITE_VAR(l);

  cout<<"sig="<<signature<<" ver="<<ver<<" type="<<type<<" dims="<<dims<<" #descriptors="<<num_descriptors<<" #images="<<num_images<<" #words="<<word_count<<endl;
  cout<<" mJfinal="<<mJfinal<<" mDtKBinMeans="<<mDtKBinMeans<<endl;

  // write centroids to file - decide which one to save!
  if(mCentroids.size()>0){
    for(uint32_t i=0; i<mCentroids.size(); ++i)
      WRITE_PTR(&(mCentroids[i]->bd[0]), dims*sizeof(mCentroids[i]->bd[0]));
  }else{
    Log::error("Could not determine which centroids to save to file!");
    return false;
  }
  //TODO: maybe save LSH buckets here? try without first
  // LSH table building should be quite fast.
  return true;
}
Esempio n. 5
0
void TextWord::status() {

  std::cout << "####################" << std::endl << "Word: " << value
            << " Instances: " << wordCount() << std::endl;
  matchTree.print();
  std::cout << "####################" << std::endl;
}
Esempio n. 6
0
int message_HTTP(char* get){
int i;

char* buffer = malloc(4* sizeof(char));
	for(i = 0; i<4 ;i++){
		buffer[i] = get[i];
	}

	if(strcmp(buffer, "GET ") != 0) 
	{
		return -1;
	}

	if(wordCount(get) != 3){
		return -1;
	}

char * http = strstr(get, "HTTP/");
	int position = http - get;

	buffer = realloc(buffer, 8 * sizeof(char));
	for(i = 0; i < 8; i++) 
	{
		buffer[i] = get[i + position];
	}

	if(strcmp(buffer, "HTTP/1.0") != 0 && strcmp(buffer, "HTTP/1.1") != 0)
	{
		return -1;
	}

	return 0;
 
}
int main(int argc, char* argv[])
{
    int i = 0;
    for(i = 0; i < argc; i++)
    {
   	    wordCount(argv[i]);
    }
    return 0;
}
int main(void)
{
	char str[100];

	printf("Word Counter\n");
	printf("============\n");
	printf("Text to be analyzed : ");
	scanf("%[^\n]", &*str);
	wordCount(str);

	return 0;
}
Esempio n. 9
0
Static voice_index0 voiceCount(Char *s_)
{
  Char s[256];
  short i, l;

  strcpy(s, s_);
  l = strlen(s);
  for (i = 0; i <= l - 1; i++) {
    if (s[i] == comma_)
      s[i] = blank_;
  }
  return (wordCount(s));
}
Esempio n. 10
0
//============================================================
// 主程式
//============================================================
int main(void)
{
//總行數
int iLineCount;
//字母的總數
int iWordCount[26];
//整理後的字母陣列
//二維其一是存字母ASCII、其二是總數
int strSaveString[26][2];
//依題目要求,需要由大到小排列
//用來儲存最大數量的字母個數
int iMaxNumber;
//用來暫存題目的每一行文字
char strPage[30][99];
int i; //Loop Used
int j; //Loop Used

//由於測資易發生雜訊,故將陣列規零
for (i = 0; i < 26; i++)
    iWordCount[i] = 0;
//輸入行數
scanf_s("%d", &iLineCount);
//將每一行資料導入
for (i = 0; i <= iLineCount; i++)
    gets_s(strPage[i]);
//檢查每一個字母
for (i = 0; i < 26; i++)
    {
    //檢查每一行內容
    for (j = 0; j <= iLineCount; j++)
        iWordCount[i] += wordCount((char)(65 + i), strPage[j]);
    //確認本字母有出現
    if (iWordCount[i] > 0)
        {
        //在字母陣列中存字母本身的ASCII
        strSaveString[i][0] = (65 + i);
        //在字母陣列中存字母總數
        strSaveString[i][1] = iWordCount[i];
        //如果出現數量最大,則記錄
        if (iWordCount[i] > iMaxNumber)
            iMaxNumber = iWordCount[i];
        }
    }
//由最大出的字母開始遞減,由大到小顯示
for (i = iMaxNumber; i > 0; i--)
    for (j = 0; j < 26; j++)
        if (strSaveString[j][1] == i)
            printf("%c %d\n", (char)strSaveString[j][0], (char)strSaveString[j][1]);
return 0;
}
int main(void){
	
	char textInput[101];                         
	int count;

	printf("\nWord Counter\n");
	printf("=============\n");

	printf("Text to be analyzed : ");
	scanf("%100[^\n]", textInput);                

	count = wordCount(textInput);	
	
	printf("Word Count          : %d\n\n", count);

	return 0;

}
Esempio n. 12
0
bool Inicio::readFile()    {
    ifstream inputFile;

    char buffer[BUF_LEN];
    try {
        if(loadDict() && loadTransitions())
            return true;

        inputFile.open(fileName, ifstream::in);

        if(inputFile.good()) {
            inputFile.readsome(buffer,BUF_LEN);
            wordCount(buffer);
        }
    }
    catch(exception& e) {
        return false;
    }
    return true;
}
Esempio n. 13
0
void fileRead()
{
    FILE *strings;
    FILE *summary;
    int size;
    int c;
    strings = fopen("strings.txt", "r");
    summary = fopen("summary.txt", "a");

    char str[100];

    while (c = getc(strings) != EOF)
    {
        fgets(str, 100, strings);
        size = strlen(str);
        wordCount(str, summary, size);
    }

    fclose(strings);
    close(summary);
}
Esempio n. 14
0
SP_spectrum _SP_readAscii(char* filename,VC_vector which,char* file,size_t line)
{
  FILE *fstrm;
  size_t i,j;
  int ok;
  long nbl,nbw;
  long nbc;
  SP_spectrum rslt;

  if(wordCount(filename,&nbl,&nbw,NULL)) return NULL;
  if((fstrm=fopen(filename,"r"))==NULL) return NULL;

  if(nbw%nbl) return NULL;
  nbc=nbw/nbl;

  rslt=_SP_allocate(nbl,nbc,file,line);
  if(!rslt) return NULL;

  MMV_malloc(rslt->name,strlen(filename)+1,char);
  strcpy(rslt->name,filename);
  ok=1;

  for(i=0;(i<nbl)&&ok;i++)
    for(j=0;(j<nbc)&&ok;j++)
      {
	if(gotoNextWord(fstrm)) 
	  {
	    ok=0;
	    break;
	  }
	if(readNumberD(fstrm,rslt->data[j]->ddata+i))
	  {
	    fprintf(stderr,"Error when reading file '%s' (line: %ld column: %ld)\n",filename,i,j);
	    exit(1);
	  }
      }
  
  if(ok==0) fprintf(stderr,"Reach end of file !!\n");
  return rslt;
}
Esempio n. 15
0
int main(int argc, char * argv[]){
    FILE * target = NULL;
    if(argc > 1){
        target = fopen(argv[1], "r");

        if(target != NULL){
            int size = wordCount(target);
            rewind(target);
            if(size > 0){
                elem_type * a;
                a = (elem_type*) malloc(size);
                int i = 0;
                int high = INT_MIN;
                int low = INT_MAX;
                while(!feof(target)){
                    int check = getLong(target);
                    if(check > 0){
                        a[i] = check;
                        if((int)a[i] > high){
                            high = (int)a[i];
                        }
                        if((int)a[i] < low){
                            low = (int)a[i];
                        }
                        ++i;
                    }
                }
                int median = (int)median(a, size);
                printf("Largest: %d\n", high);
                printf("Lowest: %d\n", low);
                printf("Median: %d\n", median);
            } else {
                printf("No ints found in file.\n");
            }
        } else {
            printf("File not found.\n");
        }
    }
    return 0;
}
Esempio n. 16
0
/*********************************************
 ** Function: main
 ** Description: reads in input string, outputs number of words in string and number of occurrences of each letter
 ** Parameters: none
 ** Pre-Conditions: none
 ** Post-Conditions: return 0
 ********************************************/
int main() {
   int letters[numLetters];	// initializes array that counts letters
   char input[size];			// initializes array storing input string

   // reads input string
   std::cout << "Input string: " << std::endl;
   std::cin.getline(input, size);
   std::cout << input << std::endl;

   letterCount(input, letters);

   std::cout << std::endl;
   // prints number of words in input string
   std::cout << "You have " << wordCount(input) << " words with these letters:" << std::endl;
   // lists occurrences of each letter
   for (int i = 0; i < numLetters; i++) {
      if (letters[i] > 0) {
	 std::cout << static_cast<char>(i+'a') << " " << letters[i] << std::endl;
      }
   }

   return 0;
}
Esempio n. 17
0
Static void applyStyles(void)
{
  short n1, n2, sn;
  Char s[256];
  Char STR2[256];

  *voices = '\0';
  *clefs = '\0';
  ninstr = 0;
  while (*cline[(long)style] != '\0') {
    n1 = voiceCount(voices) + 1;
    n2 = wordCount(voices) + 1;
    GetNextWord(s, cline[(long)style], blank_, comma_);
    curtail(s, comma_);
    sn = findStyle(s);
    if (sn == 0) {
      sprintf(STR2, "Style %s unknown", s);
      error(STR2, print);
    }
    line_no = orig_style_line[sn-1];
    applyStyle(known_style[sn-1], s, n1, n2);
    style_used[sn-1] = true;
  }
}
void gotDirectory(char * newStr){
    sprintf(newStr, "%s/", newStr); //add a slash to the end for recursion purposes 
    printf("wc: %s: Is a directory\n", newStr);
    wordCount(newStr);

}
Esempio n. 19
0
			uint32_t const * wordPointer(uint32_t n) const
			{
				ASSERT(n < wordCount());
				return &iter[n];
			}
Esempio n. 20
0
Static void applyStyle(Char *s_, Char *stylename, stave_index first_inst,
		       stave_index first_stave)
{
  Char s[256];
  Char clef[256], subline[256], subcommand[256];
  stave_index0 i, last_inst, last_stave;
  boolean continuo = false, toosoon = false, vocal = false;
  Char STR2[256];

  strcpy(s, s_);
  last_inst = first_inst - 1;
  GetNextWord(subline, s, blank_, colon_);
  while (*s != '\0') {
    GetNextWord(subline, s, semicolon, dummy);
    i = curtail(subline, semicolon);
    GetNextWord(subcommand, subline, blank_, dummy);
    if (equalsIgnoreCase(subcommand, "VOICES")) {
      sprintf(voices + strlen(voices), " %s", subline);
      last_stave = first_stave + wordCount(subline) - 1;
      last_inst = first_inst + voiceCount(subline) - 1;
    } else if (equalsIgnoreCase(subcommand, "CLEFS")) {
      strcpy(clef, subline);
      sprintf(clefs + strlen(clefs), " %s", clef);
    } else if (equalsIgnoreCase(subcommand, "VOCAL")) {
      if (last_inst < first_inst)
	toosoon = true;
      else {
	some_vocal = true;
	vocal = true;
	for (i = first_inst; i <= last_inst; i++)
	  setVocal(i, true);
      }
    } else if (equalsIgnoreCase(subcommand, "CHORAL") ||
	       equalsIgnoreCase(subcommand, "GROUP")) {
      if (last_inst < first_inst)
	toosoon = true;
      else {
	if (equalsIgnoreCase(subcommand, "CHORAL")) {
	  some_vocal = true;
	  vocal = true;
	  for (i = first_inst; i <= last_inst; i++)
	    setVocal(i, true);
	}
	if (ngroups == maxgroups)
	  error("Too many groups", print);
	else {
	  ngroups++;
	  group_start[ngroups-1] = first_stave;
	  group_stop[ngroups-1] = last_stave;
	}
      }
    } else if (equalsIgnoreCase(subcommand, "CONTINUO"))
      continuo = true;
    else {
      sprintf(STR2, "Subcommand %s in STYLE unknown", subcommand);
      error(STR2, print);
    }
    if (toosoon) {
      sprintf(STR2, "You must first give VOICES before specifying %s",
	      subcommand);
      error(STR2, print);
    }
  }
  if (vocal && continuo)
    error("A continuo instrument may not be vocal", print);
  if (wordCount(clef) != last_stave - first_stave + 1)
    error("Number of clefs does not match number of voices", print);
  if (first_stave == last_stave || continuo) {
    strcpy(instr_name[first_stave-1], stylename);
/* p2c: preamble.pas, line 185:
 * Note: Possible string truncation in assignment [145] */
  } else {
    for (i = first_stave - 1; i <= last_stave - 1; i++)
      *instr_name[i] = '\0';
  }
  if (continuo) {
    ninstr++;
    stave[ninstr-1] = first_stave;
    for (i = first_stave - 1; i <= last_stave - 1; i++)
      instr[i] = ninstr;
    return;
  }
  for (i = first_stave; i <= last_stave; i++) {
    ninstr++;
    stave[ninstr-1] = i;
    instr[i-1] = ninstr;
  }
}
Esempio n. 21
0
void Bitmap::copyFrom(Bitmap bitmap) {
  ASSERT(bitCount_ == bitmap.bitCount_);
  for (word_t i = 0, n = wordCount(); i < n; i++)
    base_[i] = bitmap.base_[i];
}
Esempio n. 22
0
			InsnIterator const operator++(int)
			{
				InsnIterator ret{*this};
				iter += wordCount();
				return ret;
			}
Esempio n. 23
0
			InsnIterator &operator++()
			{
				iter += wordCount();
				return *this;
			}
Esempio n. 24
0
/*
 * Main function of the program. First checks if a valid number of arguments is given. If there are more than 2 arguments and the first argument is not -p (where a 2nd argument HAS to be given) or there is an additional argument after the -p <word> arguments, an error is printed.
 * Otherwise, the program opens the test.dat file in read mode.
 * If the file cannot be found, an error is printed and the program exits.
 * Otherwise, the file is closed (for memory conservation) and the program loops through the command line arguments to evaluate which function should be called and executed.
 */
int main(int argc, char *argv[])
{
	int i;
	int functionCount = 0;
	if(argc == 1 || (argc > 2 && (strcmp(argv[1],"-p")!=0 || argv[3] != NULL))) /*If no input arguments are given, if there's more than 2 arguments given and the first argument is not a -p (meaning another argument has to be included with it) OR there's more than 3 arguments passed to the program:*/
	{
			fprintf(stderr,"Error: Invalid number of arguments passed.\n"); /*Standard error is printed and help function is run as dictated by instructions.*/
			help();
	}
	else /*If argument checks are OK, open the test.dat file in read only mode.*/
	{
		FILE *testdat = fopen("test.dat","r");
		if(testdat == NULL) /*If the test.dat file does not exist, an error is printed and program is terminated.*/
		{
			fprintf(stderr,"Error: File cannot be found.\n");
			exit(0);
		}
		else /*If the program can open the file, it closes it to save space.*/
		{
			fclose(testdat);
			for(i=0; i < argc; i++) /*Loops through each input argument*/
			{
				if(strcmp(argv[i],"-p") == 0) /*If argument is -p and a word is given after -p by the user, the test.dat file is opened and the prefix function is run.*/
				{
					if(argv[i+1] != NULL)
					{
						testdat = fopen("test.dat","r");
						functionCount++;
						prefix(argv[i+1], testdat);
					}
					else /*Otherwise, an error is given.*/
					{
						functionCount++;
						fprintf(stderr,"Error: Need to define an input word.\n");
					}
				}
				if(strcmp(argv[i],"-w") == 0) /*If argument is -w, the test.dat file is opened and the wordCount function is executed.*/
				{
					testdat = fopen("test.dat","r");
					functionCount++;
					wordCount(testdat);
				}
				if(strcmp(argv[i],"-l") == 0) /*If argument is -l, the test.dat file is opened and the lineCount function is executed.*/
				{
					testdat = fopen("test.dat","r");
					functionCount++;
					lineCount(testdat);
				}
				if(strcmp(argv[i],"-h") == 0) /*If argument is -h, the help function is executed.*/
				{
					functionCount++;
					help();
				}
			}
			if (functionCount == 0) /*If no valid input arguments are passed to the program,*/
			{
				fprintf(stderr,"Error: No valid input arguments given.\n");
				help();
			}
		}
	}
	return 0; /*In order to meet C standards, the main function must return an int. 0 indicates successful program execution.*/
}
Esempio n. 25
0
void Bitmap::clear() {
  for (word_t i = 0, n = wordCount(); i < n; i++)
    base_[i] = 0;
}
Esempio n. 26
0
			uint32_t word(uint32_t n) const
			{
				ASSERT(n < wordCount());
				return iter[n];
			}