Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "md5.h"
- #define MAXWORD 255
- #define MAXCOMMAND 5
- void parseCommand(char *line, char *cmd, char *username, char *password) {
- int i,j,word;
- char **current = &cmd;
- for(i=0, j=0, word=0; i<strlen(line); ++i, ++j) {
- if (line[i] == '\n') {
- (*current)[j] = '\0';
- return;
- }
- else if(line[i] == ' ' && word == 0) {
- (*current)[j] = '\0';
- ++word;
- current = &username;
- j=0;
- }
- else if(line[i] == '\t' && word == 1) {
- (*current)[j] = '\0';
- ++word;
- current = &password;
- j=0;
- }
- else {
- (*current)[j] = line[i];
- }
- }
- }
- int main (int argc, char *argv[])
- {
- char cmd[MAXCOMMAND];
- char username[MAXWORD];
- char password[MAXWORD];
- char line[MAXWORD];
- int i;
- for (i = 0; scanf("%s", line) == 1; ++i) {
- parseCommand(line, cmd, username, password);
- printf("%s", cmd);
- printf("%s", username);
- printf("%s", password);
- if (strcmp(cmd, "quit")) {
- return 0;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment