#include <stdio.h>
#include <string.h>
#define NUM_DEF 7
struct dicionario {
char palavra[20];
char definicao[50];
};
int procString (const struct dicionario lingua[], const char
procurar[], int numPalavra) {
for (int i = 0; i < numPalavra; i++) {
if (strcmp(lingua
[i
].
palavra, procurar
) == 0) { return i;
}
}
return -1;
}
int main(void) {
const struct dicionario portu[NUM_DEF] = {
{"pao","comida de farinha"},
{"feijao","comida brasileira"},
{"tropeiro","tipo de feijao"},
{"queijo","comida de minas"},
{"macarrao","comida de vo"},
{"mortadela","comida de carne"},
{"pizza","comida da italia"}};
printf("Digite uma palavra:\n"); char palavra[20] = {'\0'};
int resultadoPesquisa = procString(portu, palavra, NUM_DEF);
if (resultadoPesquisa != -1) {
printf("%s\n", portu
[resultadoPesquisa
].
definicao); } else {
printf("Palavra n encontrada"); }
}
//https://pt.stackoverflow.com/q/246722/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2RlZmluZSBOVU1fREVGIDcKCnN0cnVjdCBkaWNpb25hcmlvIHsKICAgIGNoYXIgcGFsYXZyYVsyMF07CiAgICBjaGFyIGRlZmluaWNhb1s1MF07Cn07CgppbnQgcHJvY1N0cmluZyAoY29uc3Qgc3RydWN0IGRpY2lvbmFyaW8gbGluZ3VhW10sIGNvbnN0IGNoYXIgCnByb2N1cmFyW10sIGludCBudW1QYWxhdnJhKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG51bVBhbGF2cmE7IGkrKykgewogICAgICAgIGlmIChzdHJjbXAobGluZ3VhW2ldLnBhbGF2cmEsIHByb2N1cmFyKSA9PSAwKSB7CiAgICAgICAgCXJldHVybiBpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAtMTsKfQoKaW50IG1haW4odm9pZCkgewogICAgY29uc3Qgc3RydWN0IGRpY2lvbmFyaW8gcG9ydHVbTlVNX0RFRl0gPSB7CiAgICB7InBhbyIsImNvbWlkYSBkZSBmYXJpbmhhIn0sCiAgICB7ImZl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