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.

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

done making :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.