C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 7th, 2013, 03:54 PM
ele9 ele9 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 ele9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 39 m 22 sec
Reputation 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; } 



Reply With Quote
  #2  
Old February 7th, 2013, 05:08 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,161 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 13 h 43 m 52 sec
Reputation Power: 1736
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?

Reply With Quote
  #3  
Old February 7th, 2013, 05:26 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
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:
Quote:
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.

Reply With Quote
  #4  
Old February 8th, 2013, 01:52 PM
ele9 ele9 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 ele9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 39 m 22 sec
Reputation 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 !!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > [C] correct a code , convert phrase

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap