use of colon in C

This is a discussion on use of colon in C within the C Programming forums, part of the General Programming Boards category; Code: FILE *fp = fopen ("file.txt", "r"); if (fp != 0){ do{ x = 0; do{ a = fgetc (fp); ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    67

    use of colon in C

    Code:
    FILE *fp = fopen ("file.txt", "r");
    	if (fp != 0){
        do{
    	x = 0;
    	do{
    	a = fgetc (fp);
    	if (a != ' ' && a != '\n' && 
    		a != EOF && a !=',' && 
    		a !=';' && a !='.'&& 
    		a !='!' && a !='?'
                    a != ':'){
    	  word[x] = a;
    	  x++;
    	  }else{
    	if (x != 0){
    		word[x] = '\0';
    	    t = insertList (word, t);
    		}
    	}
          }while (a != ' ' && a != '\n' && 
    			  a != EOF && a !=',' && 
    			  a !=';' && a !='.'&& 
    			  a !='!' && a !='?'
                              a != ':');
    the function reads in characters from a file and puts the words into a list, apart from the characters specified in ' '. when i specify a colon as a character i want excluded i get a lot of errors from a compiler. how can i fix that?
    Last edited by Salem; 01-01-2008 at 09:32 AM. Reason: Fix code tags

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by agentsmith View Post
    Code:
    FILE *fp = fopen ("file.txt", "r");
    	if (fp != 0){
        do{
    	x = 0;
    	do{
    	a = fgetc (fp);
    	if (a != ' ' && a != '\n' && 
    		a != EOF && a !=',' && 
    		a !=';' && a !='.'&& 
    		a !='!' && a !='?'
                    a != ':'){
    	  word[x] = a;
    	  x++;
    	  }else{
    	if (x != 0){
    		word[x] = '\0';
    	    t = insertList (word, t);
    		}
    	}
          }while (a != ' ' && a != '\n' && 
    			  a != EOF && a !=',' && 
    			  a !=';' && a !='.'&& 
    			  a !='!' && a !='?'
                              a != ':');
    the function reads in characters from a file and puts the words into a list, apart from the characters specified in ' '. when i specify a colon as a character i want excluded i get a lot of errors from a compiler. how can i fix that?
    You forgot the && for the colon.

    Use a forward slash '/', rather than a backslash '\', for the code end tag, and your postings will looks much better.
    Last edited by Adak; 01-01-2008 at 06:06 AM.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,941
    The problem is not the colon, but the missing && between a !='?' and a != ':'.

    By the way, the closing code bbcode tag is /code, not \code.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    cheers problem fixed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcat() added an unnecessary colon
    By slowcoder in forum C Programming
    Replies: 5
    Last Post: 09-29-2006, 02:32 PM
  2. comma and semi colon
    By studentc in forum C Programming
    Replies: 13
    Last Post: 05-14-2004, 05:49 PM
  3. colon in the structure
    By shiju in forum C Programming
    Replies: 4
    Last Post: 12-11-2003, 08:41 AM
  4. another question on using The colon :
    By kes103 in forum C++ Programming
    Replies: 8
    Last Post: 08-11-2003, 11:22 AM
  5. single colon
    By kes103 in forum C++ Programming
    Replies: 11
    Last Post: 07-17-2003, 04:21 PM

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