Hi, i seem to be getting this error a lot, one of the main problems is i don't understand what it really means. The code i was writing below today was just a linked list to store and print out a set of phone numbers.
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct L
{
char *number ;
struct L *next ;
} list ;
list insertnumber( char *NUMBER, list *n1 )
{
list *n ;
n = malloc( sizeof( list ) ) ;
n -> number = NUMBER ;
n -> next = n1 ;
return n ;
free(n) ;
}
void printl( list *n )
{
while( n != NULL )
{
printf( "%s\n", n -> number ) ;
n = n -> next ;
}
}
int main( void )
{
char num[15] ;
int i ;
list *n = NULL ;
//num = malloc( sizeof( list ) ) ;
/*while( num != '.' )
{
for( i = 0 ; i < 15 ; i++ )
num[i] = getchar() ;
num = insertnumber( n, num ) ;
}*/
while( num[0] != '.' )
{
scanf( "%16s", num ) ;
n = insertnumber( num, n ) ;
}
printl( n ) ;
return 0 ;
}
I've tried it both times messing around with input. Currently it's using scanf with getchar commented out. Also should i try to be using getchar more than scanf?? I hear bad things about scanf. Right well anyway back to the point im getting these compile errors:
nlist.c: In function `insertnumber':
nlist.c:16: error: incompatible types in return
nlist.c: In function `main':
nlist.c:47: error: incompatible types in assignment
Any feedback on these errors would be much appreciated. I'm brushing up on C over Christmas and have found my real weakness is debugging, so any feedback would be welcome.
Cheers.