Help with creating a file algorithm. c

Asked

Viewed 25 times

-2

Hello I’m having trouble developing an algorithm that reads a.txt file, fix the text and create the result in another output file. The read process should occur line by line, but the input file has the following syntax error. The input file has a problem where several lines are repeated strings from previous line, differentiating from only one character. The algorithm must have a function that compares the two strings return 0 if they are equal and 1 if a character is different. If more characters are different, return the number of different characters between them.

t

you

tes

test

test

exit: "test"


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

// cada linha não deverá ter mais que 1000 caractere//


int Comparar(char *s1, char *s2) {

    int i, j;

    while (*s1) 
        s1++;

    while (*s2) {
        *s1 = *s2;
         s2++;
         s1++;

    }
    *s1 = '\0';
}

int main(int argc, char *argv[]) {


    char Linha[1000]

    FILE *arquivo;
    arquivo = fopen("entrada.txt", "r");
    if (arquivo == NULL) {
        printf("Nao foi possivel abrir o arquivo \n");
           return 1;

    }
    while (fgets(Linha, 1000, arquivo) != NULL)
        printf("%s", arquivo);
        fclose(

  if (argc != 3) 
{
    printf("\nExecute o programa da forma:\n");

    return 0;

  }
  • 1

    It seems to me you haven’t pasted your code fully and correctly.

1 answer

-1

I will redo the function today to try to show how it would look. I basically need a function that fixes this string syntax. It does not complete the sentence, just breaks it in several lines. Then while performing this fix, save in a ".txt file", which would be output. If you read the file with the function fgets and pass as one of the parameters 500, which would be the character number, you would already read this line after line and define only the (EOF) as delimiter. Correct? This my function I think will be able to handle this syntax error.

B

Br

Bra

Bras

Brasi

Brazil

char* Comparar(char *s1, char *s2) {
int i, j;

for (i = 0; s1 != '\0'; ++i); {

   for (j = 0; s2[j] != '\0'; ++j, ++i) {
      s1 = s2[j];

} S1 = ' 0'; Return S1; }

Browser other questions tagged

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