Thread: invalid char to char conversion?

  1. #1
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    invalid char to char conversion?

    invalid char to char(pointer) conversion?

    here is what i tried.

    devcpp. winnapp.
    Code:
      char    *buff;
    
     buff = (char*)GlobalAlloc( GPTR, textlen + 1);
    
    
    
       buff =   buff[strcspn ( buff, "\n" )] = '\0'; 
    
    get error
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `char' to `char*' 
    
         buff =   GPTR buff[strcspn ( buff, "\n" )] = '\0'; 
    
    get error
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `int' to `char*' 
    
         buff =   GPTR buff[strcspn ( GPTR buff, "\n" )] = '\0';
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `int' to `char*' 
    
    
    
      buff =    buff[strcspn ( GPTR buff, "\n" )] = '\0'; 
    
    2668 C:\Dev-Cpp\Project6\main.c expected `)' before "buff" 
    
    
    
         buff =    buff[strcspn ( (GPTR) buff, "\n" )] = '\0';  
    
    2668 C:\Dev-Cpp\Project6\main.c expected `)' before "buff" 
    
    
       buff =  (GPTR)  buff[strcspn ( (GPTR) buff, "\n" )] = '\0';
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `int' to `char*' 
    
    
         buff =    buff[strcspn ( (char *) buff, "\n" )] = '\0';  
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `char' to `char*' 
    
    
     buff =    buff[strcspn (  &buff, "\n" )] = '\0';  
    
    2668 C:\Dev-Cpp\Project6\main.c cannot convert `char**' to `const char*' for argument `1' to `size_t strcspn(const char*, const char*)' 
    
        buff =    buff[strcspn (  buff, '\n' )] = '\0';  
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `char' to `const char*' 
    
      buff =    buff[strcspn (  buff, "\n" )] = "\0";  
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `const char*' to `char' 
    
     buff =    buff[strcspn (  buff, (char *) "\n" )] = '\0';
    
    2668 C:\Dev-Cpp\Project6\main.c invalid conversion from `char' to `char*' 
    
    and back to the origial 
    
     buff =    buff[strcspn (  buff,  "\n" )] = '\0'; 
    
    
      (char pointer ==> buff)  =  (char pointer ==> buff)[strcspn( (char pointer ==> buff) , (string ==> "\n" ) )] = ( char ==> '\0' ) ;
    
    so....
    
      buff =    buff[strcspn (  buff,  "\n" )] = GPTR '\0';
    
    after adding (char *) one at a time then compile each of the three
    
     buff =    (char *) buff[strcspn (  buff, (char *) "\n" )] = (char *) '\0'; 
    
    get error
    
    2668 C:\Dev-Cpp\Project6\main.c [Warning] cast to pointer from integer of different size 
    
    <wimpers> arrrrgggghhhh! This prog needz a flee bath! </wimpers>

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > buff = buff[strcspn ( buff, "\n" )] = '\0';
    What exactly were you hoping to achieve here?

    I mean, why are you trying to update the buff pointer itself, when all you're doing is zeroing out the newline.

    In other words, try
    buff[strcspn ( buff, "\n" )] = '\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.

  3. #3
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    Yay! that worked! was trying to replace the '\n' with '\0' in a winnapp.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid conversion from (void *) to unsigned char
    By k0k33 in forum C Programming
    Replies: 1
    Last Post: 02-19-2009, 08:57 AM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM