Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Ayudaaaaaaaaa!!!!!!!!!no se q hacer!!!???

Estas en el tema de Ayudaaaaaaaaa!!!!!!!!!no se q hacer!!!??? en el foro de C/C++ en Foros del Web. #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; const int INITIAL_LIST_CAPACITY = 20; void build_wordlist (string* word_list, int capacity, string filename) { ...
  #1 (permalink)  
Antiguo 12/06/2009, 11:31
 
Fecha de Ingreso: junio-2009
Mensajes: 1
Antigüedad: 14 años, 10 meses
Puntos: 0
Pregunta Ayudaaaaaaaaa!!!!!!!!!no se q hacer!!!???

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

const int INITIAL_LIST_CAPACITY = 20;

void build_wordlist (string* word_list, int capacity, string filename) {

ifstream words;
string word;
int size = 0;

// Allocate the space for the word list
word_list = new string[INITIAL_LIST_CAPACITY];
capacity = INITIAL_LIST_CAPACITY;

// Open the file
words.open (filename.c_str());

if (!words) {
cerr << "Could not open " << filename << endl;
exit(EXIT_FAILURE);
}

// Loop to read in words
words >> word;
while (!/*no*/ words.eof()) {

// If there isn't enough space, grow the array and copy the contents
if (size > (capacity - 1)) {

// Create another array that is twice as large as the word_list
string new_word_list = *(new string[2 * capacity]);

// Copy the words from the word_list into the new array
for (int index = 0; (index < capacity); index++) {
new_word_list = word_list[index];
}

delete word_list;
*word_list = new_word_list;

capacity *= 2;
}

// Save the word
word_list[size] = word;
size++;

// Read in next word
words >> word;
}

words.close();
}

int main (int argc, char *argv[]) {

// An array of string objects to store our
// word list.
string *word_list = 0;
int capacity = 0;

// Read the word list file
build_wordlist (word_list, capacity, "words.txt");

// Print out the words
for (int index = 0; (index < capacity) && (word_list[index] != "");
index++) {
cout << word_list[index] << endl;
}

return EXIT_SUCCESS;
}

Hice todo este programa pro no puedo ver q tngo malo, lo he revisado pro no se q tengo malo , alguien q me ayude talvez m corrijan el o los errores.
Y q me digan por favor q le cambiaron y porque....para asi hacer una retroalimentacion con su informacion
PURA VIDA!!!!
  #2 (permalink)  
Antiguo 12/06/2009, 17:30
Avatar de hades87  
Fecha de Ingreso: diciembre-2007
Ubicación: Barcelona - España
Mensajes: 3.194
Antigüedad: 16 años, 4 meses
Puntos: 68
Respuesta: Ayudaaaaaaaaa!!!!!!!!!no se q hacer!!!???

A ver, especifica bien el título, que con ese título uno no sabe ni que hacer y segundo que problema hay? por que no esperarás que te revisen todo el programa y te lo limpien así por que si, no?
__________________
No diseñes usando tablas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:20.