RSS Forums RSS
Please support our C advertiser: Programming Forums

using arrays and adding to an array

Join Date: Jun 2006
Location: India
Posts: 7,054
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 372
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: using arrays and adding to an array

  #6  
Jul 10th, 2006
I think this prog solves the prob of both the original poster and Mr. Dilip. Hope this helps. If any portability prob or any other prob in the code then let me know.
#include <stdio.h>
#include <ctype.h>
int main()
{
char a[26];
int i;
printf("Enter the string: ");
fgets(a, 100, stdin); // safer than scanf()
i = 0;
while (a[i] && isalpha(a[i])) // check input is alphabet
{
if (isupper(a[i]))
a[i] = tolower(a[i]); // is this wat the OP wanted?
// no need to check bounds due to the nature of the prob stmt
if ((a[i] >= 'a') && (a[i] <= 'm')) 
{
a[i] += 13; 
}
// to other check req as this will always be greter than 'm' and less than equal to 'z'
else 
{
a[i] -= 13;
}
a[i] = toupper(a[i]); // is this wat the OP wanted?
i++; 
} 
fputs(a, stdout);
getchar();
return 0;
}
See ya.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:33 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC