Thread
:
Word processor
View Single Post
Word processor
Reply
Posted 2004-11-13, 11:36 AM
I am trying to create a program that a common error that users often make is that they forget the caps locks on an print text like this: "tHIS IS A SAMPLE of an error", this usually happens at the beginning of a new sentence. Write a program to detect this error and fix it. The input will be a long string on keyboard. Basically I am trying to change: "tHIS IS A SAMPLE of an error" to "This is a simple of an error." The only error I got is "isalpha"
#include <stdio.h>
#include <string.h>
main()
{
char sent [30];
int length=0, i=0, capCount=0, endLoop=0;
printf ("Enter sentence up to 30 characters:\n" );
gets (sent);
length=strlen(sent);
for (i=0; i<length; i=i+1)
{
if (sent[i]>65 && sent [i]<91)
{
capCount= capCount+1;
sent[i]=sent[i]+32;
}
}
for(i = 0; i < length && endLoop == 0; i++)
{
if(isalpha(sent[i]))
{
sent[i] -= 32;
endLoop = 1;
}
}
printf("--------------------------------------\n" );
printf("There was(were) %d capitalized letters.\n" , capCount);
printf("The sentence after ridding the caps is as follows:\n" );
printf(" %s\n", sent);
getchar();
getchar();
return 0;
}
Profile
PM
WWW
Search
deadlock75