Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *
- getRequestNick(char *msg)
- {
- char *ptr;
- char *nick;
- int i = 0;
- if((nick = malloc(sizeof(char) * strlen(msg))) == NULL)
- return NULL;
- ptr = strchr(msg, ' ');
- while(*ptr++ != '\r')
- nick[i++] = *ptr;
- return nick;
- }
- char *
- getRequestChan(char *msg)
- {
- char *sub;
- sub = strtok(msg, " ");
- while(sub)
- {
- if(sub[0] == '#')
- return sub;
- sub = strtok(NULL, " ");
- }
- return NULL;
- }
- char *
- getRequestMsg(char *msg)
- {
- char *ptr;
- if((msg = malloc(sizeof(char) * strlen(msg))) == NULL)
- return NULL;
- ptr = strrchr(msg, ':');
- puts(ptr);
- return ptr;
- }
- int
- main(void)
- {
- char str[] = ":CalebDelnay!calebd@localhost PRIVMSG #mychannel :Hello everyone!";
- printf("nickname -> %s\nchannel -> %s\nmessage -> %s\n", getRequestNick(str), getRequestChan(str), getRequestMsg(str));
- return 0;
- }
Add Comment
Please, Sign In to add comment