Solved

getenv

Posted on 2003-10-25
16
1,093 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
  • 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
 

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: 9620350
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now