B
bildad
I like fixing things so I'm working on programs from books that came in a
package deal with Borland C++ 4.52. I'm trying to fix them to compile with
gcc 3.4.2. I don't understand what's causing the following error but I
think it might have something to do with malloc(). Any insight appreciated.
DAY01E4.C:10: error: invalid conversion from `void*' to `char*'
/* Day 1: Exercise 4 */
#include <stdlib.h>
#include <stdio.h>
#define MAX 100
int main(void) // was void main(void)
{
char * string;
string = malloc( MAX );
printf( "Enter something: " );
// gets( string );
fgets( string, sizeof(string), stdin ); // to replace gets()
puts( string ); /* do something like printing */
free( string );
return 0; // for int main()
}
package deal with Borland C++ 4.52. I'm trying to fix them to compile with
gcc 3.4.2. I don't understand what's causing the following error but I
think it might have something to do with malloc(). Any insight appreciated.
DAY01E4.C:10: error: invalid conversion from `void*' to `char*'
/* Day 1: Exercise 4 */
#include <stdlib.h>
#include <stdio.h>
#define MAX 100
int main(void) // was void main(void)
{
char * string;
string = malloc( MAX );
printf( "Enter something: " );
// gets( string );
fgets( string, sizeof(string), stdin ); // to replace gets()
puts( string ); /* do something like printing */
free( string );
return 0; // for int main()
}