problem with "comparison between pointer and integer"

This is a discussion on problem with "comparison between pointer and integer" within the C Programming forums, part of the General Programming Boards category; this still isn't working for me and I am frustrated. eh, I shall learn soon enough to get out of ...

  1. #1
    unregistered
    Guest

    Angry problem with "comparison between pointer and integer"

    this still isn't working for me and I am frustrated. eh, I shall learn soon enough to get out of stupid little problems. If u can improve the source... like making it so that it takes the whole file, rather than 255 bytes, that would be wonderful... but I just want it to work. thx.

    /* should parse html files for tags, dumping them to stdout - my very first program... by p0wp0wpanda*/
    #include <stdio.h>

    char partoffile[255];
    int a,b,c;

    int main()
    {

    fgets(partoffile,255,stdin);

    for (a = 0;a < 255;a++)
    if (partoffile[a] == "<") {
    for (b = a;a < 255;a++)
    if (partoffile[b] == ">") {
    for (c = a-b;c<b;c++)
    putc(partoffile[c],stdout);
    };};}

  2. #2
    Unregistered
    Guest
    I havent analyzed your code at all, but you definately need to put those "<" and ">" into single quotes, ie '>' and '<'. This is probably what your compiler is warning about, because your array element is a single character, and "<" is a char*, which are not going to compare too well. If you use '>' you are looking at the individual char > as opposed to the > char followed by the (hidden) '\0' char. Good luck.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    6
    Thx, I mean now it compiles and all, but it still doesn't seem to be working... could anybody try to help me to get it to work? thx.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Use code tags when you post code.
    Paste the code straight in from the editor.
    Return 0; from main.
    If you haven't posted all your code above, please paste it all.
    The world is waiting. I must leave you now.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is this program supposed to do?

    /* should parse html files for tags, dumping them to stdout - my very first program... by p0wp0wpanda*/

    So does it just dump all of the tags themselves? This is very easy.

    Code:
    #include <stdio.h>
    int main ( void )
    {
        FILE *fp = NULL;
        int c = 0;
    
        if( (fp = fopen( "myfile.html", "r" )) != NULL)
        {
            while( (c = fgetc( fp )) != EOF )
            {
                if( c == '<' )
                {
                    do printf( "%c", c ); while( (c = fgetc( fp )) != EOF && c != '>' );
                    printf(">\n");
                }
            }
            fclose( fp );
        }
        else
            printf("Error opening file.\n");
        return 0;
    }
    I didn't compile it, but this should do the trick.

    Quzah.
    Last edited by quzah; 05-24-2002 at 11:13 PM.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    6
    *jaw drops* I didn't know that was possible. Soooo fast... so easily made to be scriptable... yes... good... THX! It is wonderful. Lol, thx.

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    6
    speaking of scripting, I know that I am doing something wrong below, could anybody help in fixing it? (it won't open the file that I pass as an argument...)

    #include <stdio.h>
    int main (char *filename)
    {
    FILE *fp = NULL;
    int c = 0;

    if( (fp = fopen(filename, "r" )) != NULL)
    {
    while( (c = fgetc( fp )) != EOF )
    {
    if( c == '<' )
    {
    do printf( "%c", c ); while( (c = fgetc( fp )) != EOF && c != '>' );
    printf(">\n");
    }
    }
    fclose( fp );
    }
    else
    printf("Error opening file.\n");
    return 0;
    }

  8. #8
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    #include <stdio.h> 
    int main (int argc, char * argv[]) 
    { 
    	FILE * fp = NULL;
    	int c = 0; 
    
    	if (argc == 2)
    	{
    		if( (fp = fopen(argv[1], "r" )) != NULL) 
    		{ 
    			while( (c = fgetc( fp )) != EOF ) 
    			{ 
    				if( c == '<' ) 
    				{ 
    					do printf( "%c", c ); while( (c = fgetc( fp )) != EOF && c != '>' ); 
    					printf(">\n"); 
    				} 
    			} 
    			fclose( fp ); 
    		} 
    		else 
    		printf("Error opening file.\n"); 
    	}
    	return 0; 
    }
    Is that what you're looking for?

    The command line arguments could be handled a bit better in this example, but it will get a file open for you to do your work.

    I created a file, and put this in it:
    <b>hmm</b>
    and it printed the bold html tags.
    The world is waiting. I must leave you now.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    6
    Thx, it works really well now.

Popular pages Recent additions subscribe to a feed

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