Solved

getenv

Posted on 2003-10-25
16
1,099 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
partition customisation for kickstart file 2 92
Problem to command 8 93
how can i fully uninstall a puppet client? 2 102
Error while installing rpm 1 77
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

929 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

20 Experts available now in Live!

Get 1:1 Help Now