Amazon.com Widgets Chapter ten exercise 13 a little help here before I peek at the answer.
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 10:59:32 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in C, 3rd ed. (Stephen Kochan)
| |-+  Questions and Help
| | |-+  Chapter ten exercise 13 a little help here before I peek at the answer.
Pages: [1]   Go Down
Print
Author Topic: Chapter ten exercise 13 a little help here before I peek at the answer.  (Read 1103 times)
A31Chris
Newbie
*
Posts: 20


Email




« on: February 13, 2012, 11:58:03 PM »

Here is the output I'm getting from my solution to this. Its got me a little baffled why its converting every non cap to a lowercase 'a'.

Code: (Objective-C)
A Test To Remove All Non-Capitals!
Now Making All Capitals!
A Tααα Tα Rααααα Aαα Nαα-Cααααααα!

haha! gots me scratching my head a bit. OK I'll be back in a few days to see if anyone can give me a clue what I'm doing wrong.

Code: (Objective-C)
//Program to convert lowercase to upper case.

#include <stdio.h>

void upperCase(char string[80])
{
int j;

for(j=0;string[j]!='\0';j++)
{
if(string[j]>='a' && string[j]<='z')
{
string[j]=-'a'+'A';
}


}
return;
}

int main(void)
{
char testString[80]="A Test To Remove All Non-Capitals!";

printf("%s\n",testString);

printf("Now Making All Capitals!\n");

upperCase(testString);

printf("%s",testString);


getchar();
return 0;
}
Logged
Waiting
Global Moderator
Full Member
*****
Posts: 103






« Reply #1 on: February 14, 2012, 03:43:45 AM »

That looks like an alpha symbol rather than an a.

What does   string[j]=-'a'+'A' do ?
Logged
A31Chris
Newbie
*
Posts: 20


Email




« Reply #2 on: February 18, 2012, 01:30:46 AM »

Alright I've been trying to reply but this forum software is acting asinine.

It substracts the asci value of 'a' from the character variable c, then adds the asci value of 'A' to it. This formula produces the lowercase to capital letter result of alphabetic characters.

And I peeked at the answer after a few days of being stumped. My error was a syntax error.

string[j]=-'a'+'A';

should be:

string[j]=string[j]-'a'+'A';
Logged
mitchb
Jr. Member
**
Posts: 98






« Reply #3 on: March 03, 2012, 05:21:03 PM »

Hex 20 is the difference between lower case and upper case. The space character happens to be hex 20.

The statement string[j] = string[j]-'a'+'A'; the 'a' + 'A' can be replaced with a space.

string[j] = string[j]-' ';

Mitch
Logged

If you give a man a program, you will frustrate him for a day;
If you teach him how to program, you will frustrate him for a lifetime;
     - Anonymous
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.