Guest User

Untitled

a guest
Jan 21st, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "md5.h"
  4.  
  5. #define MAXWORD 255
  6. #define MAXCOMMAND 5
  7.  
  8. void parseCommand(char *line, char *cmd, char *username, char *password) {
  9.  
  10. int i,j,word;
  11. char **current = &cmd;
  12.  
  13. for(i=0, j=0, word=0; i<strlen(line); ++i, ++j) {
  14. if (line[i] == '\n') {
  15. (*current)[j] = '\0';
  16. return;
  17. }
  18. else if(line[i] == ' ' && word == 0) {
  19. (*current)[j] = '\0';
  20. ++word;
  21. current = &username;
  22. j=0;
  23. }
  24. else if(line[i] == '\t' && word == 1) {
  25. (*current)[j] = '\0';
  26. ++word;
  27. current = &password;
  28. j=0;
  29. }
  30. else {
  31. (*current)[j] = line[i];
  32. }
  33. }
  34.  
  35. }
  36.  
  37. int main (int argc, char *argv[])
  38. {
  39. char cmd[MAXCOMMAND];
  40. char username[MAXWORD];
  41. char password[MAXWORD];
  42.  
  43. char line[MAXWORD];
  44.  
  45. int i;
  46.  
  47. for (i = 0; scanf("%s", line) == 1; ++i) {
  48.  
  49. parseCommand(line, cmd, username, password);
  50.  
  51. printf("%s", cmd);
  52. printf("%s", username);
  53. printf("%s", password);
  54.  
  55. if (strcmp(cmd, "quit")) {
  56. return 0;
  57. }
  58.  
  59. }
  60.  
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment