URL splitter

This is a discussion on URL splitter within the C Programming forums, part of the General Programming Boards category; So I have this assignment for C course. I am quite lost about where to even start. Any help would ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    33

    URL splitter

    So I have this assignment for C course. I am quite lost about where to even start. Any help would be appreciated.

    Read a URL (assume http protocol) as a string from stdin. Extract from the URL, the domain name, relative path name, name-value pairs in the query string. Print the following with appropriate ids.
    URL
    domain name
    path name
    the name-value pairs in the form "(name, value)"


    You need to organize the program so that each task is accomplished by a function with minimal code clustering in the main program. For this assignment assume that URL has the format "http://...[?...=...&...&...=...]". The string that follows the ? is called query-string. It consists of name-value pairs separated by '&'. The name and the corresponding value are separated b '='. You may assume that the URLS are similar to the ones shown in the examples below. Assume that the valid URLS will have "https://" as a prefix. If the prefix is missing, treat it as an incorrect URL, print that with an error message, and continue to process the next line of input. You must implement and use the folliwng functions.

    split(s,c,sl,sr) - splits a string s into two substring sl and sr. sl is the portion of the string to the left of c and sr is the portion following c. if the string does not contain c, sl is a copy of s and sr is empty string. This is a utility function called by other ........ions. It returns true if c is found in s, otherwise it returns false. s and c are input paramenters, and sl and sr are output parameters. Assume that all parameters are strings.

    get_name_value(inp,name,value) - inp is input parameter (in general) of the form "name=value". name and value are output parameters. this function returns true if the string inp is of the correct form, otherwise retruns false. All parameters must be strings.

    get_name_value_pair(s,nvp,tail) - splits a string s into two substrings nvp and tail. nvp is the portion of s preceding the first '&' in s, and tail is the substring following '&'. It returns true if s contains an '&', otherwise false. All must be strings.

    get_domain(s,d) - extracts the domain d, from s

    get_path(s,p) - extracts the path p from s

    valid(s) - checks if the prefix of s is "http://". if the prefix is "http://" return 1, else return 0.

    the functions get_name_value, get_name_value_pair, get_domain, and get_path must use the function split to extract the component strings.

    You must use only the parameters specified.

    assume one url at a time.

    example

    input - http://www.google.com/search?hl=en&q=ibm
    output -
    URL: http://www.google.com/search?hl=en&q=ibm
    Domain name: http://www.google.com
    relative path name: search
    name-value pairs are as follows:
    (hl,en)
    (q,ibm)
    Last edited by monki000; 02-17-2010 at 04:45 PM.

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    11
    You have the same assignment as I do.......are you in OSU c/c++ programming class?

  3. #3
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    What have you done so far?

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    11
    I have the same assignment as this user and I started out with

    Code:
    split(char s; char c; char sl; char sr) 
    int main(void) 
    {
       int i = 0; 
       char sl, sr, s, c;
       char *chptr, name, value;
       char sentence[15][80], a[10], b[100]; 
    
       printf("Please enter a URL."); 
       fgets(sentence, 80, stdin);
       for(chptr = sentence; *chptr != '\n'; chptr++);
       *chptr = '\0';
    
       while(i>7)
       { 
           sentence[i] = a[i]; 
           i++; 
       }
    
       if(strcmp(a[i], "http://"))
       { 
           exit(0);
       }
    
       while(sentence[i] != b[i])
       {
           sentence[i] = b[i]; 
           i++;
       }
       printf("The domain name:", b[i]);
    I'm not sure if this is correct or not

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    33
    yeah same class, whats your email crazyazn? or shoot me a pm.

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    11

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    If you guys are in the same class I want to warn you that while working together is okay (in my opinion, I don't know about your instructor), sharing your entire code like CrazyAzn might get you into trouble.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    11
    I'm not sharing......plus the code that I typed up there is possibly wrong. I'm confused on the program assignment. I have no idea what to do....I want to know if my code up there is write or not.

  9. #9
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,656
    write or not
    It's not right at all.

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    11
    Quote Originally Posted by rags_to_riches View Post
    It's not right at all.
    ha-ha.....*sigh* I'm tired.....made a typo

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    11
    I changed the program and I want to know if I'm going in the right track. If so how do I complete the assignment?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define MAXLINE 100
    
    int split(char s[],char c[],char sl[],char sr[])
    {
    
       }
    
    
    int get_name_value(char inp,char name,char value)
    {
        printf("Enter URL:"); 
        fgets(userInput, sizeof(userInput), stdin);
    }
    
    int get_name_value_pair(char s,char nvp,char tail)
    {
          
    }
    
    int get_domains(char s,char d)
    {
        
    }
    
    int get_paths(char s,char p)
    {
        
    }
    
    int valid(char s)
    {
        s = "http://";
        char sCheck[7];
        char validUrl[] = "http://";
        int i = 0;
        for (i=0;i<7;i++){
        sCheck[i]=s;}
        if (strcmp(sCheck,validUrl))
        printf("valid URL");
        else
        printf("Invalid URL");    
    }
    
    int main(void) 
    {
    
        char stringName[stringSize];  
        int intArrayName[intArraySize]; 
        int methodName(char stringName[], int intArrayName[]);
        int i = 0, a[7], b[100];
        char userInput[80]; 
    
        printf("URL: ");
        printf("\nDomain name: ");
        printf("\nRelative path name: ");
        printf("\nName-Value pairs are as follows: \n");
        system("pause");
    }

  12. #12
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    You need to take this one step at a time, or else you'll never make any progress. You need to compile AND TEST your code at each step. Right now you have a bunch of code with errors all over the place that won't even compile.

    First, see if you can read in the user input and print it back out.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make URL connection and read from URL
    By abmirayo in forum C Programming
    Replies: 3
    Last Post: 02-15-2010, 04:59 PM
  2. Programmatically Activating A Splitter
    By SMurf in forum C# Programming
    Replies: 3
    Last Post: 02-14-2009, 09:16 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  4. Replies: 1
    Last Post: 07-02-2007, 10:22 AM
  5. Static Splitter Problem
    By dhrodrigues in forum Windows Programming
    Replies: 0
    Last Post: 05-19-2005, 06:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21