Solved

getenv

Posted on 2003-10-25
16
1,100 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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