Is this a bug?

Discussion in 'C Programming' started by Edilberto Del Cid, May 27, 2018.

  1. Edilberto Del Cid

    Edilberto Del Cid

    Joined:
    May 27, 2018
    Messages:
    1
    Likes Received:
    0
    So im currently making a program that analyze a string and detects whether if written backwards is the same as if its written normally(palindrome) so i made the code using strlen and 2 for loops, 1 to make the string without spaces and the other one to analyze whether its a palindrome, everything is fine but when the code reaches to the second for loop the strlen of the second string(the one without spaces) shows a wrong number preventing me from analyzing the string. Here is the code:


    char cadena3[100];
    int tamanodc=0;
    char letradc;
    int numdecece=0;
    char cese1[100];
    int f;
    int tamanodeces;
    printf("Ingrese Cadena para verificar:");
    gets(cadena3);
    tamanodc=strlen(cadena3);
    for(i=0;i<tamanodc;i++){
    letradc=cadena3;
    if(letradc!=' '){

    cese1[numdecece]=cadena3;
    numdecece++;
    }

    }
    tamanodeces=strlen(cese1);
    printf("%i",tamanodeces);
    for(f=0;f<tamanodeces;f++){
    printf("lo lograste");
    }
    system("pause");
    when i get to this point, if i write a 3 caracter string the for loop somehow causes it to be another number. i dont understand
     
    Edilberto Del Cid, May 27, 2018
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.