split an entry of the form Last/First into two parts : Pointer String « Pointer « C / ANSI-C






split an entry of the form Last/First into two parts

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

char *my_strchr(char *string_ptr, char find){
    while (*string_ptr != find) {
       if (*string_ptr == '\0')
           return (NULL);
       ++string_ptr;
    }
    return (string_ptr);
}

int main()
{
    char line[80]="asdf";
    char *first_ptr;
    char *last_ptr;

    line[strlen(line)] = '\0';
    last_ptr = line;
    first_ptr = my_strchr(line, 'd');

    if (first_ptr == NULL) {
        fprintf(stderr,"Error: Unable to find 'a' in %s\n", line);
    }
    return (0);
}


           
       








Related examples in the same category

1.Reverse string content using its pointerReverse string content using its pointer