The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
[C] correct a code , convert phrase
Discuss [C] correct a code , convert phrase in the C Programming forum on Dev Shed. [C] correct a code , convert phrase C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2013, 03:54 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 10
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; }
|

February 7th, 2013, 05:08 PM
|
 |
Lord of the Dance
|
|
|
|
|
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?
|

February 7th, 2013, 05:26 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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.
|

February 8th, 2013, 01:52 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 10
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 !!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|