problem on assignment

This is a discussion on problem on assignment within the C Programming forums, part of the General Programming Boards category; hi guys: I got a problem on my assignment. On my assignment program, it needs to find out the open ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Unhappy problem on assignment

    hi guys:
    I got a problem on my assignment. On my assignment program, it needs to find out the open tag and close tag of html string and find the index of the string within open tag and close tag.

    I also start my program with following code:

    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>

    int getPoints(char html[], char tagname[], int tagnum, int *start, int
    *end);

    int getPoints(char html[], char tagname[], int tagnum, int *start, int
    *end)
    {
    int track;
    int index;
    int words;
    int i;
    int j;
    int k;
    int a;
    int b;
    int get;
    int put;

    track = strlen(html);

    for (j=0; j<track; j++)
    {
    html[j] = toupper(html[j]);
    }
    printf("%s\n",html);

    for(b=0; b<track; b++)
    {
    tagname[b] = toupper(tagname[b]);
    }
    printf("%s\n",tagname);

    index = strlen(tagname);

    put = 0;

    for (i=0; i < track; i++)
    {
    if (html[i] == '<' && (html[i+index] = tagname[i]) &&
    html[i+index+1] == '>')
    {
    if (put != tagnum)
    put++;

    if (put = tagnum)
    *start = i + index + 2;

    }

    else
    {
    *start = 0;
    words = 0;
    return words;
    }
    }

    get = put;

    for (a=0; a>track; a++)
    {

    if(html[a] == '<' && html[a+1] == '/' && (html[a+1+index] =
    tagname[a]) && html[a+2+index] == '>')
    {
    if (get != tagnum)
    {
    get--;
    }
    if (get = tagnum)
    {
    *end = a - 1;
    }
    }

    else
    {
    *end = 0;
    words = 0;
    return words;
    }
    }

    words = *end - *start + 1;
    return words;
    }


    void main()
    {
    int r;
    int s;
    int e;

    r=getPoints("what the <P> hfasbgka</P>fkkhgwag<p>sdjhfkjhjkasg</p>",
    "p",1,&s,&e);

    }

    I compile on my school AIX platform, it's runned but the compiler showed the statement Segmentational Fault(coredump). I don't know what's wrong on my program and which parts of my program i need to fix

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Because you're trying to modify a string constant

    > "what the <P> hfasbgka</P>fkkhgwag<p>sdjhfkjhjkasg</p>"
    This is stored in read only memory

    > html[j] = toupper(html[j]);
    And this tries to modify it, which is a no-no

    Try this
    Code:
    int main ( ) {  // yes, main returns int - ALWAYS
        char test[] = "what the <P> hfasbgka</P>fkkhgwag<p>sdjhfkjhjkasg</p>";
        int r,s,e;
        r=getPoints( test, "p",1,&s,&e);   
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment problem
    By cboard_member in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2006, 02:16 PM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. Another assignment problem
    By the_winky_files in forum C Programming
    Replies: 14
    Last Post: 10-03-2005, 11:33 AM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. homework assignment problem
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-29-2001, 10:24 AM

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