[ create a new paste ] login | about

Link: http://codepad.org/AyOgA3x9    [ raw code | output | fork ]

hmurcia - C++, pasted on Jul 31:
/* Arreglo de arreglos (cadenas de texto). Manejo.
   En funciones como parĂ¡metros */
//
#include <iostream>
using namespace std;

int tamanio(const char *[]);
void mostrar(const char *[]);
void msgPausado(const char []);

int main() {
    const char *palabra[] = {"hello", "good", "bye", "thing", "thanks", "roll", "over",
         "subway", "ceil", "floor", "adventure", "always", "anything",
         "bother", "brother", "sister", "mother", "father", "love", "beautiful",
         "scramble", "history", "argument", "library", "flower", "student", "teacher",
         "another", "decision", ""};

    srand(time(0));
    cout << "There are " << tamanio(palabra) << " words:\n\n";
    mostrar(palabra);
    msgPausado("\n\nPulse <ENTER> para continuar ...");
    system("cls");

    int t = rand()%tamanio(palabra);
    msgPausado(palabra[t]);
}

int tamanio(const char *array[]) {
    int i = 0;
    while(strcmp(array[i], ""))
        i++;
    return i;
}

void mostrar(const char *array[]) {
    int i = 0;
    while(strcmp(array[i], ""))
        if (strlen(array[i])>7)
            cout << array[i++] << ((i-4)%4 ? "\t" : "\n");
        else
            cout << array[i++] << ((i-4)%4 ? "\t\t" : "\n");
}

void msgPausado(const char mensaje[]) {
    cout << mensaje;
    cin.get();
}


Output:
1
2
3
4
cc1plus: warnings being treated as errors
In function 'void mostrar(const char**)':
Line 39: warning: operation on 'i' may be undefined
Line 41: warning: operation on 'i' may be undefined


Create a new paste based on this one


Comments: