Word Array

Nov 17, 2010 at 5:18am
I was wondering if you all could help me get ideas on how to work a word array. I need helping on building an array, not predefined, and getting a .txt file and loading it into this array. Afterwards I need to figure out how to binary search this array. I am not asking you all to build it but I just want ideas cause I really have no idea how to tackle this problem.
Nov 17, 2010 at 5:36am
Try looking up the functions malloc, qsort, and bsearch from stdlib.h.
EDIT: also strcmp and fgets from string.h and stdio.h respectively.
Last edited on Nov 17, 2010 at 5:40am
Nov 17, 2010 at 5:45am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  ifstream file("yourfile.txt");
  vector<string> words;
  string word;
  while (file >> word)words.push_back(word);
  sort(words.begin(),words.end());
  if (binary_search(words.begin(),words.end(),"word_to_be_searched_for"))cout << "File contains the word." << endl;
  else cout << "File does not contain the word." << endl;
}


You might or might not be supposed to implement the binary search yourself.

rocketboy9000 wrote:
Try looking up the functions malloc, qsort, and bsearch from stdlib.h.
EDIT: also strcmp and fgets from string.h and stdio.h respectively.

This ain't a C forum.
Last edited on Nov 17, 2010 at 5:46am
Nov 17, 2010 at 7:33am
I think I see where you are going with this but how do you make the array that will size up to fit any list you give it.

Here is a sample of the list I need to use.
###########################################################################
#Copyright 1999 The Internet Dictionary Project/Tyler Chambers
#http://www.june29.com/IDP/
#This file is free to use and modify. Thank you for using the IDP.
#
#Approximately 5048 entries. 9/21/97
#Approximately 5488 entries. 1/7/98
#Approximately 5910 entries. 3/8/98
#Approximately 7450 entries. 2/19/99
###########################################################################
a un, uno, una[Article]
aardvark cerdo hormiguero
aardvark oso hormiguero[Noun]
aardvarks cerdos hormigueros
aardvarks osos hormigueros
ab prefijo que indica separacio/n
aback hacia atras
aback hacia atrás,take aback, desconcertar. En facha.
aback por sopresa, desprevenidamente, de improviso
aback atra/s[Adverb]
abacterial abacteriano, sin bacterias
abacus a/baco
abacuses a/bacos
abaft A popa (towards stern)/En popa (in stern)
abaft detra/s de[Adverb]
abalone abulo/n
abalone oreja de mar (molusco)[Noun]
abalone oreja de mar[Noun]
abalones abulones
abalones orejas de mar (moluscos)[Noun]
abalones orejas de mar[Noun]
abandon abandonar
abandon darse por vencido[Verb]
abandon dejar
abandon desamparar, desertar, renunciar, evacuar, repudiar
abandon renunciar a[Verb]
abandon abandono[Noun]
abandoned abandonado
abandoned dejado
abandoned desamparado
abandoned olvidado
abandoned abandonada,abandonado, abandonados, abandonadas[Verb]
abandonee abandonado
abandonee aislado
abandonee dejado
abandonee desamparado
abandonee money
abandoner abandonador
abandoning abandonando
abandoning abandono
abandonment abandono
abandonment desamparo, deserción
abandonments abandonos
abandons abandona
abandons desampara
abase abatir
abase abatir, envilecer
abase denigrar[Verb]
abase rebajar, humillar, degradar
abase rebajar, degradar, humillar, abatir[Verb]
abased degradado
abased rebajado, humillado, degradado
abased rebajado, degradado, humillado, abatido[Adjective]
abasement envilecimiento
abasement humillacio/n, degradacio/n
abasement rebajacio/n, degradacio/n, humillacio/n, abatimiento[Noun]
abasements humillaciones, degradaciones
abaser humillador
abases degrada; humilla[Verb]
abash avergonzar
abash avergonzar, abochornar, confundir[Verb]
abash avergonzar, confundir,
abashed avergonzado
abashes avergu.enza; pone en situacio/n embarazosa[Verb]
abashing vergonzante, vergonzoso
abashing vergonzoso
abashment Vergüenza.
abashment verguenza
abasing humillante
abasing humillante, degradante[Verb]
abate amainar[viento, tormenta], abolir, descontar, calmarse[dolor, tormenta]bajar[inundación][Verb]
abate disminuir, reducir, mitigar
abate mitigar
abate terminar, hacer cesar
abated amainado, amplacado, mitigado
abated aplacado, abolido, descontado, disminuido.NO AMPLACADO[Adjective]
abatement Abolición, supresión
abatement descuento, rebaja
abatements Rebajas, descuentos, decaimientos,aboliciones
abatements s. descuento, rebaja, decaimiento
abater rebajador, mitigador[Noun]
abates satélites
abating superando una marca; disminuyendo; situacio/n depresiva[Verb]
abating deprimente, calmante, aboliendo, disminuyendo, amainando, rebajando. NO SUPERAR UNA MARCA, en castellano es batir una marca: break a record
abatis barricada con alambre de púas, parapeto de troncos caídos
abatis tala, abatida, barricada de alambre de púas
abatises Barricads, parapetos, obstáculos
abatises sesame[Adjective]
abatises Barricadas
abattoir degolladero, macelo, matadero.
abattoir matadero de reses
abattoir matadero (GB)[Noun]
abaxial abacial
abaxial extraaxial
abaxial No situado en el eje, lejos del eje, desalineado. NO ES CORRECTO ABACIAL=ABBATIAL
abaxial abaxial, (Anatomi/a) aquella regio/n de un o/rgano alejada del eje[Adjective]
abbacy Abadía, convento, monasterio.
abbacy abadi/a
abbas ABBA= Padre, Dios. ABBAS, tío de Mahoma.
abbas aint
abbe abate
abbe ABBÉ=Abate
abberations Aberración
abberations aberracion
abberations desvi/o
abberations UNKNOWN WORD IN ENGLISH
abbey abadi/a
abbey abadía[Noun]
abbeys Abadías, monasterios, conventos
abbeys abadi/as
abbot Abad
abbot abad
abbots abades
abbots Abates. NO ABADES.
abbreviate abreviar
abbreviate Abreviar, simplificar.
abbreviate acortar[Verb]
abbreviate abreviar
abbreviated abreviado
abbreviated Abreviado, simplificado, acortado, reducido.NO CORTADO.
abbreviated cortado
abbreviates abrevia
abbreviates Reducciones, resúmenes, abreviaciones, compendios.
abbreviating abreviando
abbreviation abreviacio/n
abbreviation abreviatura
abbreviation abreviatura[Noun]
abbreviations abreviaciones
abbreviations abreviaturas
abbreviator abreviador
abc abc
abc abecedario
abdicable abdicable, que puede abdicar
abdicate abdicar
abdicate renunciar a; abdicar[Verb]
abdicated abdicado (participio de abdicar)
abdication abdicacio/n
abdication renuncia; abdicación (de un monarca)[Noun]
abdicator abdicador
abdomen abdo/men
abdomen abdomen[Noun]
abdomen (inf.)barriga, vientre
abdomens abdomenes
abdomens abdo/menes[Noun]
abdomens abdómenes[Noun]
abdominal abdominal

Nov 17, 2010 at 8:34am
vector is such an "array". The concept is called dynamic array.
Topic archived. No new replies allowed.