Untitled

 avatar
unknown
plain_text
2 years ago
1.1 kB
6
Indexable
int main ()
{
    FILE *ficheiro;
    char linha[100];
    while (fgets(linha, sizeof(linha), ficheiro) != NULL)
    {
        int tamanho = strlen(linha);
        if (linha[tamanho-1] == '\n')
        {
            linha[tamanho-1] = '\0';
        }

        if (tamanho > 1);
        {
            int posicao_paberto = strchr(linha, '(');
            if (posicao_paberto != NULL)
            {   
                int posicao_pfechado = strchr(linha, ')');
                char dentro_do_parenteses [100];
                strncopy(dentro_do_parenteses, posicao_paberto + 1, posicao_pfechado - posicao_paberto - 1);

                if (strstr(dentro_do_parenteses, "Lisboa") == NULL && strstr(dentro_do_parenteses, "Lisbon") == NULL)
                {
                    linha[posicao_paberto] = '\0';
                }
                else
                {
                    linha[posicao_pfechado + 1] = '\0';
                }
            }
        }
        fprintf(ficheiro, "%s\n", linha);

    }
    fclose(ficheiro);
}
Editor is loading...
Leave a Comment