Thread: help with array of char and char **

  1. #1

    help with array of char and char **


    I'm trying to figure out how to take an array of char and a char ** expression as parameters and have the function convert a sequence of digits it finds to type int and return the converted value, and set the contents of its second parameter ( a char * value) to point to the first character in the array that was not converted. For example if the array contained the string 555jack then after the call, the output would contain the value 555 and point to the 'j' in the string. This is what i have so far but stuck now as to what to do or add:

    #include <string.h>
    #include <stdio.h>

    int conv( char [], char **);
    int main(void)
    int intval;
    char array [80], *remainder;
    char *string = "555 jack \n ";
    printf (string);

    while ( gets( array ) !=NULL ) {
    intval = conv( array, &remainder );
    printf( " %d, %s\n", intval, remainder);

    return 0;

    Any kind of help would be very appreciated. Thank you for your time.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > int conv( char [], char **);
    Put some variable names in the prototypes - it does no harm, but it does help to document the function.

    int conv( char array[], char **remainder );

    Try writing conv like this
    int conv ( char array[], char **remainder ) {
      char *p = array;
      // increment p, and build a result
      // update the remainder pointer
      *remainder = p;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  2. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  3. code help required
    By Yobbo in forum C Programming
    Replies: 9
    Last Post: 09-02-2005, 11:15 PM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM