Thread: Can someone help me?

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    5

    Question Can someone help me?

    whats wrong with this code:

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    char le1;
    char le2;
    char le3;
    char le4;
    
    int main() {
    
        printf("Teclea una letra");
        scanf("%c", &le1);
        printf("Teclea otra letra");
        scanf("%c", &le2);
        printf("Teclea otra letra");
        scanf("%c", &le3);
        printf("Teclea otra letra");
        scanf("%c", &le4);
        printf("Estas son tus letras al inversa con comillas "%c%c%c%c"", le4, le3, le2, le1);
        
        getch();
    
        }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You include conio.h when you could have just used getchar in stdio.h.
    You use globals when you don't need to.
    Your main() should really be main( void ).
    You don't return 0; at the end of main.

    Other than that, you should ask smart questions.

    edit - What you are probably asking about is why it seems to skip every other letter you enter one at a time. That's because you press enter after you type each one, but you don't take that into account when you try to read your letters.


    Quzah.
    Last edited by quzah; 05-11-2011 at 05:44 PM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    5
    Thanks, I corrected everything you said.
    But When i try to compile, it throws me an error in the last printf : c was not declared on this scope.

    What's wrong?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You will need to post your actual code, because you don't have anything called c in the example you posted. It sounds like you have a quotation mark in the wrong spot.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    5
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    char le1;
    char le2;
    char le3;
    char le4;
    
    int main(void) {
    
        printf("Teclea una letra");
        scanf("%c", &le1);
        printf("Teclea otra letra");
        scanf("%c", &le2);
        printf("Teclea otra letra");
        scanf("%c", &le3);
        printf("Teclea otra letra");
        scanf("%c", &le4);
        printf("Estas son tus letras al inversa con comillas "%c%c%c%c"", le4, le3, le2, le1);
    
        getchar();
        return 0;
            }
    Sorry, if you dont understand the content of the prinfs, it's in spanish. I'm from Uruguay

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Read up on string literals and escape sequences in your textbook. You use " to start a string, and " to end it. But how will the compiler know if you actually want to put a " in the middle of a string? It doesn't. You have to tell it to make the " part of the string by prefixing it with a \, like so:
    Code:
    printf("Estas son tus letras al inversa con comillas \"%c%c%c%c\"", le4, le3, le2, le1);

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    5
    Thanks

Popular pages Recent additions subscribe to a feed