Problem with char and char*

This is a discussion on Problem with char and char* within the C Programming forums, part of the General Programming Boards category; I have got a lot of errors from the line which has the 3 if statements in it. Code: C:\WINDOWS\Desktop\code.c(21): ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    43

    Problem with char and char*

    I have got a lot of errors from the line which has the 3 if statements in it.

    Code:
    
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2157: Unrecognized statement.
    
    C:\WINDOWS\Desktop\code.c(21): error #2001: Syntax error; found 'if' expecting ';'.
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2157: Unrecognized statement.
    
    C:\WINDOWS\Desktop\code.c(21): error #2001: Syntax error; found 'if' expecting ';'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(47): warning #2096: Missing return value.
    
    C:\WINDOWS\Desktop\code.c(47): error #2001: Syntax error; found 'end of input' expecting '}'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2157: Unrecognized statement.
    
    C:\WINDOWS\Desktop\code.c(21): error #2001: Syntax error; found 'if' expecting ';'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2157: Unrecognized statement.
    
    C:\WINDOWS\Desktop\code.c(21): error #2001: Syntax error; found 'if' expecting ';'.
    
    C:\WINDOWS\Desktop\code.c(21): error #2168: Operands of == have illegal types 'char' and 'char *'.
    
    C:\WINDOWS\Desktop\code.c(47): warning #2096: Missing return value.
    
    C:\WINDOWS\Desktop\code.c(47): error #2001: Syntax error; found 'end of input' expecting '}'.
    How do I make the two types compatible with eachother so that the Operands of illegal types.... message goes away?

    Code:
    #include <stdio.h>
    
    int main()
    {
        FILE *f;
        char s[1000];
    
        f=fopen("file.txt","r");
        if (!f)
            return 1;
        while (fgets(s,1000,f)!=NULL)
     	{
    	printf("Test");       
    	printf("%s",s);
    	if (s[1] == "N") && if (s[2] == "O") && if (s[3] == "P") {
    		if (s[4] == 0) {
    			printf("00 00 00 00 // NOP");
    	} else {
    		 printf("Syntax error. NOP should not have anything else after it");
    }
    }
        fclose(f);
        return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    > if (s[1] == "N")
    Use single quotes for single letters
    Use strcmp or strncmp to compare strings.
    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. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  2. char problem
    By ForlornOdium in forum C++ Programming
    Replies: 10
    Last Post: 10-29-2003, 01:39 PM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  4. String Processing Problem
    By muffin in forum C Programming
    Replies: 0
    Last Post: 08-24-2001, 10:13 AM

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