arrays converting to isupper

I had to write a prog. to accept a string and then change every uppercase to lowercase, space to "#" and fullstop to "@" but after compilation the program displays the exactly same inputs without any change...PLS HELP !!! URGENT...

This is the program I wrote!

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
void main()
{char arr[50];
cin.getline(arr,50);
for (int i=0;i!='\0';i++)
{if (arr[i]== isupper(arr[i]))
if (arr[i]==' ')
arr[i]='#';
else if(arr[i]=='.')
arr[i]='@';}
puts (arr);
getch(); }
Last edited on
closed account (10oTURfi)
1. Thats and ugly chunk of code, use code tags
2. void main is evil, let me quote standard:
A program shall contain a global function called main, which is designated start of the program.
...
It shall have a return type of int
...



This is what you are looking for
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cctype>
using namespace std;

int main()
{
    char arr[50];
    cin.getline(arr, 50);

    for(int i=0;arr[i]; i++)
        if(isupper(arr[i]))
            arr[i] = tolower(arr[i]);

    for(int i=0; arr[i]; i++)
        cout << arr[i];

    cout << endl;

    return 0;
}
Last edited on
@krofna....thanks a ton...but ur program has 8 errors...and when I run it on turbo c++ it is unable to detect the header file cctype!....also...I had three conversions to be made ..u missed the other 2 ! but anyways...thank u so much !
Turbo C++ is really old!(but we are made to use it in school as well). You should also have one modern IDE (Like Visual C++ Express)
After changing Krofna's code for Turbo C++, it will be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <ctype.h>

int main()
{
    char arr[50];
    cin.getline(arr, 50);

    for(int i=0;arr[i]; i++)
    {
        if(isupper(arr[i]))
            arr[i] = tolower(arr[i]);
    
        if (arr[i] == ' ')
            arr[i] = '#'
        if (arr[i] == '.')
            arr[i] = '@'
    }

    for(int j=0; arr[i]; j++)
        cout << arr[i];

    cout << endl;

    return 0;
}


EDIT: Added the [code] tags!
Last edited on
Topic archived. No new replies allowed.