#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> //lider com variaveis booleans
#define NUM_DEF 7
struct dicionario
{
char palavra[20];
char definicao[50];
};
bool compString( const char palavra1[], const char palavra2[])
{
//confere os caracteres das palavras
int i=0;
while (palavra1[i]==palavra2[i] && palavra1[i] != '\0' &&
palavra2[i] != '\0')
{
++i;
}
if (palavra1[i]=='\0'&&palavra2[i]=='\0')
{
return true;
}
else
{
return false;
}
}
int procString (const struct dicionario lingua[],const char procurar[], int numPalavra) //busca a palavra no dicionario
{
int i=0;
for (i=0;i < numPalavra; ++i){
if(compString(procurar,lingua[i].palavra))
{
return i;
}
}
return -1;
}
int main(void)
{
char palavra[20];
int resultPesq;
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");
resultPesq = procString(portu,palavra,NUM_DEF);
if (resultPesq != -1)
{
printf("%s\n",portu
[resultPesq
].
definicao); }
else
{
printf("Palavra n encontrada"); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4gLy9saWRlciBjb20gdmFyaWF2ZWlzIGJvb2xlYW5zCiNkZWZpbmUgTlVNX0RFRiA3CgpzdHJ1Y3QgZGljaW9uYXJpbwp7CiAgICBjaGFyIHBhbGF2cmFbMjBdOwogICAgY2hhciBkZWZpbmljYW9bNTBdOwp9OwoKYm9vbCBjb21wU3RyaW5nKCBjb25zdCBjaGFyIHBhbGF2cmExW10sIGNvbnN0IGNoYXIgcGFsYXZyYTJbXSkKewovL2NvbmZlcmUgb3MgY2FyYWN0ZXJlcyBkYXMgcGFsYXZyYXMKICAgIGludCBpPTA7CiAgICB3aGlsZSAocGFsYXZyYTFbaV09PXBhbGF2cmEyW2ldICYmIHBhbGF2cmExW2ldICE9ICdcMCcgJiYKICAgICAgICAgICAgcGFsYXZyYTJbaV0gIT0gJ1wwJykKICAgIHsKICAgICAgICArK2k7CgogICAgfQogICAgaWYgKHBhbGF2cmExW2ldPT0nXDAnJiZwYWxhdnJhMltpXT09J1wwJykKICAgIHsKICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9Cn0KCmludCBwcm9jU3RyaW5nIChjb25zdCBzdHJ1Y3QgZGljaW9uYXJpbyBsaW5ndWFbXSxjb25zdCBjaGFyIHByb2N1cmFyW10sIGludCBudW1QYWxhdnJhKSAgLy9idXNjYSBhIHBhbGF2cmEgbm8gZGljaW9uYXJpbwp7CiAgICBpbnQgaT0wOwogICAgZm9yIChpPTA7aSA8IG51bVBhbGF2cmE7ICsraSl7CiAgICAgICAgaWYoY29tcFN0cmluZyhwcm9jdXJhcixsaW5ndWFbaV0ucGFsYXZyYSkpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIC0xOwp9CgoKaW50IG1haW4odm9pZCkKewoKICAgIGNoYXIgcGFsYXZyYVsyMF07CiAgICBpbnQgcmVzdWx0UGVzcTsKCiAgICBjb25zdCBzdHJ1Y3QgZGljaW9uYXJpbyBwb3J0dVtOVU1fREVGXSA9CiAgICB7CiAgICAgICAgeyJwYW8iLCJjb21pZGEgZGUgZmFyaW5oYSJ9LAogICAgICAgIHsiZmVpamFvIiwiY29taWRhIGJyYXNpbGVpcmEifSwKICAgICAgICB7InRyb3BlaXJvIiwidGlwbyBkZSBmZWlqYW8ifSwKICAgICAgICB7InF1ZWlqbyIsImNvbWlkYSBkZSBtaW5hcyJ9LAogICAgICAgIHsibWFjYXJyYW8iLCJjb21pZGEgZGUgdm8ifSwKICAgICAgICB7Im1vcnRhZGVsYSIsImNvbWlkYSBkZSBjYXJuZSJ9LAogICA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