#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
char s1[30],d[30];
int l;
clrscr();
cout<<"Enter your name: \n";
cin>>s1;
cout<<s1<<endl;
l=strlen(s1);
cout<<l;
d=strupr(s1);
cout<<d;
getch();
}

When i run this code , it shows Lvalue required error
please help

Dani AI

Generated

— the compiler is complaining because the left side of = must be a modifiable object. and pointed at that core issue; below are practical, safe fixes and more portable alternatives you can apply right away.

A modern C++ approach (preferred) — use std::string and std::transform with std::toupper. This avoids raw buffer management and the nonstandard strupr:

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

int main() {
    std::string s;
    std::cout << "Enter your name: ";
    if (!(std::cin >> s)) return 0;
    std::transform(s.begin(), s.end(), s.begin(),
                   [](unsigned char c){ return std::toupper(c); });
    std::cout << s << '\n' << s.size() << '\n';
    return 0;
}

If you need to stick with C-style arrays, convert characters into the destination buffer with bounds checking instead of assigning an array name:

#include <iostream>
#include <cstring>
#include <cctype>

int main() {
    char s1[30], d[30];
    std::cin >> s1;
    std::size_t l = std::strlen(s1);
    std::size_t maxCopy = std::min(l, sizeof(d)-1);
    for (std::size_t i = 0; i < maxCopy; ++i)
        d[i] = std::toupper(static_cast<unsigned char>(s1[i]));
    d[maxCopy] = '\0';
    std::cout << d << '\n';
    return 0;
}

Additional notes: avoid void main, iostream.h, and conio.h for portable code; strupr is nonstandard and may not exist on all compilers — if you do use it, assign its return to a char* (not an array) or copy its result into your buffer. Always cast to unsigned char before toupper to avoid undefined behavior, and ensure destination buffers are large enough and null-terminated.

Recommended Answers

All 3 Replies

any one here to help????????????

d=strupr(s1);

d is an array, but strupr() returns a pointer to char. That is a type mismatch on the one hand, and on the other you cannot assign to an array.

First you need to understand the error , read here

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.