Thread: Char array strings problem

  1. #1
    Registered User
    Join Date
    Feb 2010

    Char array strings problem

    First the 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
    segmentation fault
    First off:
    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:
    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:
    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, 05: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, 12:13 AM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM