#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    10
    Rep Power
    0

    [C] correct a code , convert phrase


    Hi , could someone help me with this cose. I would like to print a phrase and convert it. The part of The code about The print it's ok but ( i think ) that The problem is in The function.. Thanks


    Code:
    
    #include <stdio.h> 
    #include <string.h> 
    void toLower(char *s) { 
    int i; for (i=0; i<strlen(s); i++)
    if ( (s[i]>='A') && (s[i]<='Z') ) 
    s[i]+=32;  }   
     int main() { 
    int i;  
    char s[20];  
    printf("stampa una frase:"); 
    gets(s);  
    printf("%s\n", s);  
    toLower(s); 
    printf ("Frase convertita completamente in caratteri minuscoli: %s\n",s); 
    return 0; }
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,632
    Rep Power
    1945
    Can you correct you coding style with proper indention? it will make it easier to read.

    Also please explain what kind of conversion you want? what result do you expect?
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,155
    Rep Power
    2222
    My Italian is minimal, but the output says that the phrase is to be converted completely to lower case (miniscule as opposed to capitalized).

    ele9, your code's formatting is a problem. When we write code, we need to make it as readable as possible, which is why we keep each statement on a separate line and why we indent the code. It is more for your own benefit that you make your code readable, because you are the one who needs to be able to read it. Read this article on Wikipedia, Indent Style. I recommend the Allman style.

    Here is how your code looks properly indented in the Allman style:
    Code:
    #include <stdio.h> 
    #include <string.h> 
    
    void toLower(char *s) 
    { 
        int i; 
        for (i=0; i<strlen(s); i++)
            if ( (s[i]>='A') && (s[i]<='Z') ) 
                s[i]+=32;  
    }   
    
    int main() 
    { 
        int i;  
        char s[20];  
        printf("stampa una frase:"); 
        gets(s);  
        printf("%s\n", s);  
        toLower(s); 
        printf ("Frase convertita completamente in caratteri minuscoli: %s\n",s); 
        return 0; 
    }
    I compiled and ran your code. The only warning I got is that the variable, i, is declared in main but not used; that is one example of a non-malignant warning. Here is what I got:
    C:\otros\dcw>gcc -Wall minuscol.c
    minuscol.c: In function `main':
    minuscol.c:14: warning: unused variable `i'

    C:\otros\dcw>a
    stampa una frase:HellO.
    HellO.
    Frase convertita completamente in caratteri minuscoli: hello.

    C:\otros\dcw>
    In other words, it appears to work and produces the expected output. Is there an input string that it doesn't work for? If so, then please tell us what that input phrase is so we can test it. The only problem I can see is if the input phrase is longer than 19 characters.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    10
    Rep Power
    0
    Sorry :( i solved my problem , the code was correct but i hai problems with dev! Antivirus blocked dev when i tried to compile -_- Thanks anyway to compile my code !!

IMN logo majestic logo threadwatch logo seochat tools logo