Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

getenv

Posted on 2003-10-25
16
Medium Priority
?
1,113 Views
Last Modified: 2007-12-19
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
           switch(argc)
           {        
                  case 2:
                       
                          if(getenv(strupr(argv[1])) != NULL)
                          {
                                printf("%s = %s\n",strupr(argv[1]),getenv(strupr(argv[1])));
                          }
                          else
                          {
                                printf("%s not found\n", strupr(argv[1]));
                          }
                           
                          break;
             }
 
             return 0;
}    


I'm receiving and error stating:

Parsing arg 1 of getenv makes pointer from integer without a cast.
:undefined reference to strupr

How do I solve this problem.

Your help is kindly appreciate.

Regards
Eugene
0
Comment
Question by:eugene007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 2
  • 2
  • +1
16 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 9620133
The error indicates that the compiler has no prototype for strupr(), so it assumes the function
returns an integer.

strupr() is not in the ANSI spec or the POSIX spec, so its use is considered "non-portable".
It is quite likely that it does not exist on your system or development environment, or it
does exist, but you are compiling with -strict or -ansi.
0
 

Author Comment

by:eugene007
ID: 9620314
I am using an ANSI C. I am currently using red hat version 9.
0
 

Author Comment

by:eugene007
ID: 9620323
well the main error is this:

Parsing arg 1 of getenv makes pointer from integer without a cast.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:eugene007
ID: 9620339
so does it mean, I include the library file:

#include <sdgstd.h>

will solve my problem.
0
 

Author Comment

by:eugene007
ID: 9620432
I did the following changes:

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
           switch(argc)
           {        
                  case 2:
                       
                          if(getenv(toupper(argv[1])) != NULL)
                          {
                                printf("%s = %s\n",toupper(argv[1]),getenv(toupper(argv[1])));
                          }
                          else
                          {
                                printf("%s not found\n", toupper(argv[1]));
                          }
                           
                          break;
             }
 
             return 0;
}    


Im getting this error:

warning: passing arg 1 of 'toupper' makes integer from pointer without a cast.
warning: passing arg 1 of getenv makes pointer from integer without a cast

Regards
Eugene
0
 

Author Comment

by:eugene007
ID: 9620437
when I compile my code I do it this way:

cc environ.c -o environ
0
 
LVL 6

Expert Comment

by:GaryFx
ID: 9620574
toupper only works on a character at time.  If you don't have strupr, then write your own routine to convert the entire string to upper case (calling toupper on each character of the string).

Gary
0
 

Author Comment

by:eugene007
ID: 9620653
can u show me an example with relations to my code.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 9620685
> so does it mean, I include the library file:
>      #include <sdgstd.h>
> will solve my problem.

strupr() is usually prototyped in sdgstd.h, so that should solve your problem.





     
0
 

Author Comment

by:eugene007
ID: 9620726
well cant seem to work at all.
0
 

Author Comment

by:eugene007
ID: 9620760
"toupper only works on a character at time.  If you don't have strupr, then write your own routine to convert the entire string to upper case (calling toupper on each character of the string)."

how do I copy the argv[1] value into a char buffer[100] variable.
From this buffer variable, I loop thru it, convert each character
into a upper case character using toupper(), then store it into
another variable and use it in my program.
0
 

Author Comment

by:eugene007
ID: 9621391
ive found the solution for it. This is an example:

strcpy(task_name,argv[1]);
for(i=0;i<strlen(task_name),i++)
task_name[i] = toupper(task_name[i]);
0
 
LVL 6

Expert Comment

by:GaryFx
ID: 9622246
Yep, pretty trivial.  You don't really need to do the copy, unless you also have a need to keep the original version of the string.  However, I strongly suggest checking the length of argv[1] before doing the copy, otherwise you've created another infamous buffer overrun.

Gary
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 11560621
Closed, no points refunded.
RomMod
Community Support Moderator
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question