Mega Code Archive

 
Categories / C / Pointer
 

Split an entry of the form LastFirst 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); }