?
Solved

getenv

Posted on 2003-10-25
16
Medium Priority
?
1,114 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
15 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

862 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