forgotten how to print values :(

This is a discussion on forgotten how to print values :( within the C Programming forums, part of the General Programming Boards category; version gcc 2.95.3 SunOS 5.6 Hi, I have the following snippet Code: if (!(seq_filename = (char *)getenv(SEQ_FILE))) printf("before error_func %s\n", ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    93

    forgotten how to print values :(

    version gcc 2.95.3
    SunOS 5.6

    Hi,

    I have the following snippet

    Code:
        if (!(seq_filename = (char *)getenv(SEQ_FILE)))
    printf("before error_func %s\n", seq_filename);
    /* printf("before error_func %s\n", (char *)getenv(SEQ_FILE)); */
            error_func("In get_seq_no().",
                       "Environment variable SEQUENCE_FILE not set.",
                        SYS | FATAL);
    printf("failure: \n");
        strcpy(seq_identifier, identifier);
    and the if test is failing, my problem is, I don't seem to be able to trap what values exist when it falls over.

    I don't have access to gdb which is why I am using printf's at the mo

    Could someone show me how to print the values of a

    static char * seq_filename
    #define SEQ_FILE "SEQUENCE_FILE"



    tia,

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    93
    ty for your reply Salem

    Code:
       /* if test */
       if (!(seq_filename = (char *)getenv(SEQ_FILE)))
       {
          /* first of two printf statements */
          printf("before error_func %s\n", seq_filename);
          printf("before error_func %s\n", (char *)getenv(SEQ_FILE));
    
          /* function call if test is true */
          error_func("In get_seq_no().",
                     "Environment variable SEQUENCE_FILE not set.",
                      SYS | FATAL);
       )
       /* another printf statement */
       printf("failure: \n");
    
       /* doesn't make  it here while blowing up */
       strcpy(seq_identifier, identifier);

    from what little I know, the test either passes or fails, it cannot do both !

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    93
    I do not see anything printed, because I am using these two printf statements incorrectly

    printf("before error_func %s\n", seq_filename);
    printf("before error_func %s\n", (char *)getenv(SEQ_FILE));

    which is why I would like to know how to get the values that exist in these two items



  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    93
    Hi Salem,

    I have got away to prove what's in the ENV

    Code:
    $ cat my_getenv.c
    #include <stdio.h>
    #include <stdlib.h>
    
    char *my_getenv(char* name)
    {
       char *result;
       result = getenv(name);
    
       if(NULL == result)
          printf("my_getenv, environment variable, is not set\n");
       return result;
    }
    
    int main()
    {
       char *test;
       test = my_getenv("SEQ_FILE");
    
       if(NULL == test)
          printf("the environment variable is NULL\n");
       else
          printf("the environment variable is : %s\n", test);
    }



    thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-20-2008, 11:58 PM
  3. Replies: 1
    Last Post: 12-30-2007, 09:08 AM
  4. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 09:44 PM
  5. Sending values to a control
    By Zyk0tiK in forum C Programming
    Replies: 6
    Last Post: 12-02-2005, 05:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21