0

I have made a following program that will convert lower case letters in to upper case and upper case letters will remain same and that will be done Realtime (as character is typed).

#include<stdio.h>
#include<conio.h>
void main(void)
{
char ch;
printf("Type a sentence: ");
while (ch!='\r')
{
ch=getch();
if (ch >=97 && ch <= 122) // if lowercase
ch = ch -32; // change to lowercase
printf("%c",ch);
}
getch();
}

But now I want to add an option that, user enters a character number to capitalize.

Following should be output of the program:

Enter sentence: hello how are you?
Enter char number to capitalize: 2
Output: hEllo hOw aRe yOu?

Any help? I don't know how to get the position of character in a string.
P.S. I don't want to use any other library function or string.

Edited by WaltP: Added CODE Tags -- please use them

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by krulex
0

I have made a following program that will convert lower case letters in to upper case and upper case letters will remain same and that will be done Realtime (as character is typed).

#include<stdio.h>
#include<conio.h>
void main(void)
{
char ch;
printf("Type a sentence: ");
while (ch!='\r')
{
ch=getch();
if (ch >=97 && ch <= 122) // if lowercase
ch = ch -32; // change to lowercase
printf("%c",ch);
}
getch();
}

But now I want to add an option that, user enters a character number to capitalize.

Following should be output of the program:

Enter sentence: hello how are you?
Enter char number to capitalize: 2
Output: hEllo hOw aRe yOu?

Any help? I don't know how to get the position of character in a string.
P.S. I don't want to use any other library function or string.

1) Use CODE Tags
2) void main() -- see this
3) Format your code
4) Why not use the simple putchar() made to output a single character rather than the complex printf() ?
5) When you start reading or you input a space, zero a counter
6) For each character input, increment the counter
7) When the counter is the specified value (2 in your example) capitalize the character entered

Edited by WaltP: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.