Gender neutralizer in C!

Asked

Viewed 80 times

-4

I am a beginner in the programming area and took some basic exercises to train my lóg. de Prog. in C. And one of these questions was to develop a program that would neutralize the gender of the words inserted, such as: girls -> boys ; blacks -> blacks. I already have a pseudo-code assembled and I will leave it and the statement linked here in the body (by Pastebin.com) however, my difficulty is to create a variable to make this neutrality. Thanks in advance.

Note: this has no political bias, it is just something didactic and student to student. I appreciate the understanding.

#include <stdio.h>

//o problema já começa na declaração de variáveis, nao sei se o certo seria uma declaração em "char" mas enfim...

char genero, palavra;
     genero = x;
     palavra = a, o;

//entrada

    printf("Os pesquisadores da universidade recebem mal");

//aqui já entraria a suposta variável para neutralizar os gêneros das palavras
//ação a ser executada...

    printf("Xs pesquisadorxs dx universidadx recebem mal");

//aqui se repetiriam as 3 (três) frases

return 0;

Enunciation:

You work for the newspaper ----- ------, change all the markers gender for the letter X.

Entree

os pesquisadores da universidade recebem mal
os alunos de escola particular sao privilegiados

Exit

xs pesquisadorxs dx universidadx recebem mal
xs alunxs dx escola particular sxx privilegiadxs
  • 3

    Young, first, use tags correctly, C and C# are completely different things. Also never put your code on external sources, this makes it difficult to access people who have locks for some domains and, moreover, makes it difficult to read the question, no one wants to have to access 3 different links to try to write an answer.

  • Read a basic tutorial on declaring and assigning variables in C. With gender = x; you are assigning the contents of variable x to the gender variable, maybe you wanted to do: gender = 'x'; (assigning constant 'x' to the gender variable).

  • Why in his example the letter 'e', from the end of university, is replaced by 'x'?

  • LINQ : Thanks, I’m new here and your tips were very useful. anonimo1: Thanks, I’ll try your suggestion. anonimo2: I also found it bizarre, but it’s done from student to student, just for educational purposes so I don’t think it interferes too much.

  • Only with a parser to do what you want. To create a parser you will have to build a lexical parser with lex(or flex) plus a syntactic parser created with Yacc(or Bison) that together will act on the text based on a digital dictionary of the Portuguese language so that after you attach a token grammatical(not a syntactic token) to all words ai yes can decide which words may or may not have gender neutralized.

1 answer

2


Good afternoon @Masantm,

First of all: This is not as simple a question as it seems.

For us humans, it is very simple and easy to identify where or not the 'x' to neutralize the genres of words, but the computer performs only instructions, so it is up to us to explain the rules and exceptions.

In the example:

"The girl took the drill"

neutralizing genres would be:

"X garotx pegou na furadeira"

but the complexity lies in how to pass the instructions to the computer.

  • Attempt 1:

"Computer, exchange all letters 'o' and 'a' for 'x' "

Upshot:

"X gxrxtx pegxu nx furxdeirx"

Opa, we have already faced the first problem: It is not all the letters 'o' and 'a' that should be replaced, so that reading the sentence does not become a guessing game. In addition, we have words that have gender defined and do not have 'o' or 'a', for example: "teachers". At this point we can already see that only the letters 'o' and 'a' that are at the end of each word need to be exchanged, more precisely in the last two letters, which is where the classification of the word genres is grammatically positioned, so let’s go.

  • Attempt 2:

"Computer, change the letters 'o','a' and occasionally 'and', but only those in the last two positions of each word"

Upshot:

"X garotx pegxu nx furadeirx"

It is a better result than the previous one, but still has many problems. " Drill" is a feminine gender word, however it is an object name, so it does not enter the rule of neutral writing, as well as "caught" and "in the".

  • Attempt 3:

    "Computer, exchange the letters 'o', 'a' and occasionally 'and' for 'x', in words that relate to subjects, to neutralize their genres. as articles and adjectives, but do not change if they are objects, as they have no gender"

Upshot:

"X garotx pegou na furadeira"

Perfect, right? But passing instructions to a program is not as simple as saying "Computer, do it". To make the above instruction readable to a computer we would have to feed it a considerable amount of data and rules.

This book above was just to open your mind to the complexity that some programs can assume. I’m a computer student so I think it’s important to give you this first notion, because sometimes we let things go by "beats".

#include <stdio.h>
#include <string.h>

int main(){

char string[100];
int i;

gets(string);

for(i=0;i<100;i++){

   if(string[i] == ' '){ //Checando se o caractere em questão é um espaço
       if(string[i- 1] == 'a' || string[i- 1] == 'o'){
           string[i- 1] = 'x';
       }else if(string[i- 2] == 'a' || string[i- 2] == 'o' || string[i- 2] == 'e'){
           string[i- 2] = 'x';
       }else{
           i++;
       }
   }
}

printf(string);

return 0;
}

This is an example of code I did until the second attempt, "Computer, replace the letters 'o', 'a' and occasionally 'e' at the end of the words".

I purposely left a logic hole, can you figure out what it is? It’s nothing as complex as the problems I mentioned above and can serve you as an exercise.

I hope that knowledge will be useful to you.

Welcome to Stackoverflow and good studies!

Hug!

  • 1

    By far your answer was the one that helped the most, and I thank you very much. The comments to my question also helped but not with what I needed. Anyway, seeing your answer I realized that I need to study a little more the C language and focus on strings (I already worked with Java and it was also my biggest difficulty, I’m starting now in the area). But I thank you in advance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.