Guest User

Untitled

a guest
Jan 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *
  6. getRequestNick(char *msg)
  7. {
  8.   char *ptr;
  9.   char *nick;
  10.   int i = 0;
  11.  
  12.   if((nick = malloc(sizeof(char) * strlen(msg))) == NULL)
  13.     return NULL;
  14.  
  15.   ptr = strchr(msg, ' ');
  16.   while(*ptr++ != '\r')
  17.     nick[i++] = *ptr;
  18.  
  19.   return nick;
  20. }
  21.  
  22. char *
  23. getRequestChan(char *msg)
  24. {
  25.   char *sub;
  26.  
  27.   sub = strtok(msg, " ");
  28.   while(sub)
  29.   {
  30.     if(sub[0] == '#')
  31.       return sub;
  32.     sub = strtok(NULL, " ");
  33.   }
  34.  
  35.   return NULL;
  36. }
  37.  
  38. char *
  39. getRequestMsg(char *msg)
  40. {
  41.   char *ptr;
  42.  
  43.   if((msg = malloc(sizeof(char) * strlen(msg))) == NULL)
  44.     return NULL;
  45.  
  46.   ptr = strrchr(msg, ':');
  47.   puts(ptr);
  48.   return ptr;
  49. }
  50.  
  51. int
  52. main(void)
  53. {
  54.   char str[] = ":CalebDelnay!calebd@localhost PRIVMSG #mychannel :Hello everyone!";
  55.  
  56.   printf("nickname -> %s\nchannel -> %s\nmessage -> %s\n", getRequestNick(str), getRequestChan(str), getRequestMsg(str));
  57.   return 0;
  58. }
Add Comment
Please, Sign In to add comment