I've made some changes which seem to make more sense. Changes have been highlighted. Another question. About my input. I want to input numbers until the input reads in a full stop. But i'm missing something to put in my first while loop. Just kind of want it run ( e.g. while( there is input to be read in) if you get me ) only reason i have the while in there is so i can use the break statement.
So yeah here is my code.
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct L
{
char number[15] ;
struct L *next ;
} list ;
list *insertnumber( char NUMBER, list *n1 )
{
list *n ;
n = malloc( sizeof( list ) ) ;
n -> number[15] = NUMBER ;
n -> next = n1 ;
return n ;
}
void printl( list *n )
{
while( n != NULL )
{
printf( "%s\n", n -> number ) ;
free( n ) ;
n = n -> next ;
}
}
int main( void )
{
char *num ;
char check ;
int i ;
list *q = NULL ;
num = calloc( 15, sizeof( char ) ) ;
while( )
{
check = getchar() ;
if( check != '.' )
{
num[0] = check ;
for( i = 1 ; i < 15 ; i++ )
num[i] = getchar() ;
}
else
break ;
q = insertnumber( *num, q ) ;
}
printl( q ) ;
return 0 ;
}
The print function and stuff still isn't done, just wanted to make sure the pointers are now ok?