Char array strings problem

This is a discussion on Char array strings problem within the C Programming forums, part of the General Programming Boards category; First the code: Code: typedef struct { char *data_string } obs int string_to_num(char string_in, int *string_out) { char *temp; temp ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    84

    Char array strings problem

    First the code:

    Code:
    typedef struct {
    
    char *data_string
    
    } obs
    
    int string_to_num(char string_in, int *string_out)
    {
    
      char    *temp;
    
      temp = malloc((strlen(string_in)+1) * sizeof(char));
    
      strcpy(temp, &qstring_in);
    
      if (*temp == 'P') /* Test Passed. */
         *string_out = 1;
     
      return 0;
    }
    problem is in my code I refer to a data pointer that points to the structure and -> to the data_string.

    I don't know how to pass it as an argument into string_to_num() as its not a char but a pointer...

    Does that make sense?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    First off:
    Code:
    int string_to_num(char string_in, int *string_out)
    string_in is not even a char *ptr, it's just a single char.

    Anyway, if you have:
    Code:
    struct obs *obs_ptr;
    and you have malloc'd space for it AND the data_string inside, you can submit it to sting_to_num:
    Code:
    string_to_num(obs_ptr->data_string,...
    Beyond that, I'm glad to see you are doing this a little bit at a time rather than write the entire function first and then be puzzled at what part of it doesn't work
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The UNIX System Interface
    By rrc55 in forum C Programming
    Replies: 1
    Last Post: 10-20-2009, 06:56 PM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 10:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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