Hi everyone,
So I am writing this program that is supposed to do the following:
Create a program that accepts a string from the user (not from the command line) and displays:
1. The string using upper-case letters, e.g. all lower-case letters are converted to upper-case letters
2. The string using lower-case letters, e.g. all upper-case letters are converted to lower-case letters
3. The string where the first letter of each word is upper-case and all other letters in the word are lower-case.
4. The string in "camel case", i.e. the first letter in the string is lower case, followed by alternating upper and lower case letters
I have done everything but number 4, the first letter in the string is lower case, followed by alternating upper and lower case letters.
I could really use some help. Any tips, hints, or help is much appreciated. Thank you.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#define N 128
int main()
{
char input[N];
char c,d,j,e;
char *ptr = input;
int x,z,y;
x=0;
z=0;
y=0;
printf("Enter a string: ");
gets(input);
/*Changes user input to all lower case*/
do
{
d = input[z];
d = tolower(d);
input[z] = d;
z++;
}
while(d);
printf("Lower case: ");
puts(input);
/*Changes user input to all upper case*/
do
{
c = input[x];
c = toupper(c);
input[x] = c;
x++;
}
while(c);
printf("Upper case: ");
puts(input);
/*Capitalizes first letter of each word*/
do
{
e = input[y];
e = tolower(e);
input[y] = e;
y++;
}
while(e);
{
size_t j = 0;
/* Strip the optional newline */
input[strcspn ( input, "\n" )] = '\0';
for ( ; ; )
{
/* Ignore spans of whitespace */
while ( input[j] != '\0' && isspace ( input[j] ) )
++j;
if ( input[j] == '\0' )
break;
input[j] = (char)toupper ( input[j] );
/* Ignore spans of non-whitespace */
while ( input[j] != '\0' && !isspace (input[j] ) )
++j;
}
printf ( "FirstCap case: ");
puts(input);
}
printf("Camel case: ");
puts(input);
system("pause");
return(0);
}