Oh wow, you're right. I took out NewSentence and changed all the references to it to references to string, and it seems to work. thanks.
Heres how it looks now:
Code:
#include <stdio.h>
#include <string.h>
void reverseCase(char *string)
{
int length = strlen(string);
int i;
for(i = 0; i <= length; i++)
{
char test = string[i];
if(test >= 'a' && test <= 'z')
string[i] = test-32;
else
if(test >= 'A' && test <= 'Z')
string[i] = test+32;
else
string[i] = test;
}
}
main()
{
char sentence[] = "LoTS of ChANging Case Characters, AND STUFF like COMMAS.";
reverseCase(sentence);
printf("%s", sentence);
system("pause");
}
I also got the second one to work, thanks to toupper() and tolower(). without those it was just a mess and i couldnt keep track of what i was doing.
Here it is:
Code:
#include <stdio.h>
#include <string.h>
int countRange(char *string, char first, char last)
{
int result = 0;
if(first > last)
return 0;
if(*string == 0)
return 0;
if(first < 'A' || (first > 'Z' && first < 'a') || first > 'z' || last < 'A' || (last > 'Z' && last < 'a') || last > 'z')
return 0;
tolower(first);
tolower(last);
int i;
for(i=0; i <= strlen(string); i++)
{
if((string[i] >= first && string[i] <= last) || (string[i] >= toupper(first) && string[i] <= toupper(last)))
result++;
}
return result;
}
main()
{
int result;
char sentence[] = "ab CDEFGH.";
result = countRange(sentence, 'c', 't');
printf("%d", result);
char sentence2[] = "";
result = countRange(sentence2, 'a', 'h');
printf("%d", result);
char sentence3[] = "SOME CAPS, some small.";
result = countRange(sentence3, 'a', 'u');
printf("%d", result);
system("pause");
}