fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char url[101];
  6. fgets(url, sizeof(url), stdin);
  7.  
  8. // Remove trailing newline
  9. size_t len = strlen(url);
  10. if (len > 0 && url[len - 1] == '\n') {
  11. url[len - 1] = '\0';
  12. }
  13.  
  14. // Process the URL to remove enclosing quotes if present
  15. char *processed_url = url;
  16. if (strlen(processed_url) > 0) {
  17. if (processed_url[0] == '"' || processed_url[0] == '\'') {
  18. char quote = processed_url[0];
  19. char *end_quote = strrchr(processed_url, quote);
  20. if (end_quote && end_quote != processed_url) {
  21. *end_quote = '\0';
  22. processed_url = processed_url + 1;
  23. }
  24. }
  25. }
  26.  
  27. // Find the query part of the URL
  28. char *query = strchr(processed_url, '?');
  29. if (query == NULL) {
  30. printf("\n\n\n\n\n");
  31. return 0;
  32. }
  33. query++; // Move past the '?'
  34.  
  35. // Variables to store parameter values
  36. char *username_val = NULL;
  37. char *password_val = NULL;
  38. char *profile_val = NULL;
  39. char *role_val = NULL;
  40. char *key_val = NULL;
  41.  
  42. // Split the query into key-value pairs
  43. char *saveptr;
  44. char *pair = strtok_r(query, "&", &saveptr);
  45. while (pair != NULL) {
  46. char *eq = strchr(pair, '=');
  47. if (eq) {
  48. *eq = '\0'; // Split into key and value
  49. char *key = pair;
  50. char *value = eq + 1;
  51.  
  52. // Check which parameter the key corresponds to
  53. if (strcmp(key, "username") == 0) {
  54. username_val = value;
  55. } else if (strcmp(key, "pwd") == 0) {
  56. password_val = value;
  57. } else if (strcmp(key, "profile") == 0) {
  58. profile_val = value;
  59. } else if (strcmp(key, "role") == 0) {
  60. role_val = value;
  61. } else if (strcmp(key, "key") == 0) {
  62. key_val = value;
  63. }
  64. }
  65. pair = strtok_r(NULL, "&", &saveptr);
  66. }
  67.  
  68. // Output the values in the specified order
  69. printf("%s\n", username_val ? username_val : "");
  70. printf("%s\n", password_val ? password_val : "");
  71. printf("%s\n", profile_val ? profile_val : "");
  72. printf("%s\n", role_val ? role_val : "");
  73. printf("%s\n", key_val ? key_val : "");
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 5284KB
stdin
"http://w...content-available-to-author-only...p.com/signin/service?username=test&pwd=test&profile=developer&role=ELITE&key=manager"
stdout
test
test
developer
ELITE
man