Invalid conversion from void to char

This is a discussion on Invalid conversion from void to char within the C Programming forums, part of the General Programming Boards category; Hey guys, I have a problem with this code not compiling. The compiler says that the bolded line is an ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    46

    Invalid conversion from void to char

    Hey guys, I have a problem with this code not compiling. The compiler says that the bolded line is an invalid conversion from void to char but I don't understand why this won't work. Thanks all!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void quiz(char *s);
    
    void quiz(char *s)
    {
    
         char *t = malloc(strlen(s) + 1);
    
         char *p = t;
    
         while (*s)
         {
               if (!('a' <= *s && *s <= 'z'))
               {
    
                  *p = *s;
    
                  p++;
               }
    
               s++;
         }
    
         *p = '\0';
    
         printf("%s",t);
    }
    
    int main()
    {
          char array[] = "I heart CS262";
          
          quiz(array);
    
          return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,570
    I suggest using a newer C Compiler.

    Or, using the old way of casting the return of malloc.

    Tim S.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    You are probably compiling as C++ rather than C.

    AAAAANNNNDDDD...cross-posted

  4. #4
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    you can cast it, check to make sure it's not being compiled as C++ code, or get a newer Compiler as stahta01 suggested
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    46
    Quote Originally Posted by rags_to_riches View Post
    You are probably compiling as C++ rather than C.

    AAAAANNNNDDDD...cross-posted
    Oh, thank you sir.

    Also, this exam is in an hour and I am just trying to get answers ASAP.

    Thanks for all the help guys!

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    > Also, this exam is in an hour and I am just trying to get answers ASAP.
    In other words, it was "urgent".

    How To Ask Questions The Smart Way
    Not our problem.

    Try to imagine a world where every selfish person in a hurry cross-posts the SAME thing on many different forums.
    How much of the limited FREE time that helpers provide is going to be spent on wasted duplicate effort?
    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.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by askinne2 View Post
    Oh, thank you sir.

    Also, this exam is in an hour and I am just trying to get answers ASAP.

    Thanks for all the help guys!
    Do I understand you to say you're sitting in an exam as you post this?

    WOW... cheating has just moved to a whole new level.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My code wont link with gcc but does with Visual Studio
    By moniker in forum C Programming
    Replies: 2
    Last Post: 12-19-2009, 04:08 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  5. Can't Find Conio.h?
    By drdroid in forum C++ Programming
    Replies: 27
    Last Post: 09-26-2002, 04:24 AM

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