Re: Help a beginner - simple lowercase to uppercase and so on function



On 28 July, 00:40, "bpascal...@xxxxxxxxxxxxxx"
<bpascal...@xxxxxxxxxxxxxx> wrote:

I'd first say thanks for your replies.
I'd study carefully what was said here, at this time i'm not sure i
can understand everything but it should take shape with more practice
of C.
I don't spend too much time thinking before i post because it's not
certain i'll keep studying at that pace.

do more thinking


For the code, I think (a little late) the mistake that made it not
work (compile and return something) is about thses loops where <= n
was replaced with < n (the '\0' can't be uppercase):

don't think, test! By which I mean, don't guess that your code works;
test it.

main :
for ( i = 0 ; i < n ; i++ )
{
if ( (Txt1[i] <= 'a' ) || (Txt1[i]>= 'z') )

printf("\nThere are no lowercase
letters in this string !\n\n") ;
else
UppStrg(&Txt1[i], &Txt2[i], n) ;
}

void UppStrg :

for ( i = 0 ; i < cnt ; i++ )
*(Upp+i) = *(Low+i) - 'a' + 'A';

With these modification, it compiles and returns uppercase letters
however not regarding if true or not "There are no lowercase letters
in this string !" in gcc linux.

sorry I didn't understand that


In Windows djgpp it just doesn't compile unless the loop in main looks
like :

for ( i = 0 ; i < n ; i++ )
UppStrg(&Txt1[i], &Txt2[i], n) ;

please post the complete coce that compiles under gcc Linux but not
under Windows djgpp. At the core it's the same compiler so it *ought*
to compile on both.

Some posts above seem to tell why. I'll read them carefully again.

I'd expect this code to make upppercase a whole string and not just
one charactere entered at a time if i answer right your question.

the question was (or should have been) "does the function UppStrg()
convert a single character to upper case or does it convert the whole
string?". If it converts the entire string how many times would you
expect your code to call it? How many times does your program call it?


Ok,
this code is not taking many consideration such as non ascii letters
or uppercase letters... Also the non-official purpose is to put at
work my understanding of loops and functions which needs more work
regarding the time i have spent on this i think.

About the spacing : I first find it easier to spot mistakes

whilst making it harder for every other C programmer in the galaxy.
Please switch to a more conventional layout. It will become readable
with practice.

and i have
read spacing would play a role in other languages such as python.

well you aren't programming in Python at the moment.

I'm
not preparing to switch to python this way yet, i'd like a good
understanding of c maybe to program with linux os...i don't know what
i'll be able to do and when.

In english we have the expression "don't change horses in mid-stream".
So stick with one language until you're reasonably happy with it.
Then learn another one. The first language is the hardest.


--
Nick Keighley

"Programs must be written for people to read, and only
incidentally for machines to execute."
- Abelson & Sussman, Structure and Interpretation of Computer Programs


.


Quantcast