It looks like the line
head = (Node*) malloc( sizeof( Node ) ); //line 21
is outside the main()
function. You can’t do that, because you can’t execute code outside functions. The only thing you can do at global scope is declaring variables. Just move it inside the main()
or any other function, and the problem should go away.
(PS: Take a look at this question on why you shouldn’t type-cast malloc
)
Related Posts:
- typedef struct pointer definition
- typedef struct vs struct definitions [duplicate]
- Why should we typedef a struct so often in C?
- Why should we typedef a struct so often in C?
- typedef struct vs struct definitions [duplicate]
- Pointer Arithmetic
- dereferencing pointer to incomplete type
- char *array and char array[]
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- How do you make an array of structs in C?
- Difference between a Structure and a Union
- Difference between char* and const char*?
- #31 expression must have integral type
- How do you pass a function as a parameter in C?
- Invalid pointer error on invoking free() after malloc in C
- How to initialize a struct in accordance with C programming language standards
- expression must have integral type
- Incompatible implicit declaration of built-in function ‘malloc’
- What’s wrong with my code? What is argv[1]?
- Valgrind: Invalid read of size 1
- Constant pointer vs Pointer to constant
- What is the cause of flexible array member not at end of struct error?
- Reversing a string in C
- size of struct in C
- Warning: return from incompatible pointer type in C
- Warning: assignment from incompatible pointer type
- strcmp giving segmentation fault
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- What is the difference between char array and char pointer in C?
- Scanning Multiple inputs from one line using scanf
- Dereference void pointer
- The difference between char * and char[] [duplicate]
- lvalue required as increment operand
- How to use execvp()
- How to use execvp() to execute a command
- How does strtok() split the string into tokens in C?
- what is Segmentation fault (core dumped)? [duplicate]
- How to convert an int to string in C?
- How to print in C
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What does the question mark character (‘?’) mean?
- makefile:4: *** missing separator. Stop
- Stack smashing detected
- How do I determine the size of my array in C?
- What is the difference between C and embedded C?
- Undefined reference to pthread_create
- What is Bit Masking?
- what is the meaning of == sign?
- How do I use extern to share variables between source files?
- Cannot assign requested address – possible causes?
- error: called object is not a function or function pointer
- munmap_chunk(): invalid pointer
- No Symbol Table using GDB on Compiled Programs
- What is char ** in C?
- Difference between scanf() and fgets()
- Return char[]/string from a function [duplicate]
- Is there a printf converter to print in binary format?
- What is a bus error? Is it different from a segmentation fault?
- Output single character in C
- Get the current time in C
- error: expected primary-expression before ‘)’ token (C)
- Does connect() block for TCP socket?
- Converting a C program to MIPS
- Get text from user input using C
- How do I lowercase a string in C?
- warning: expression result unused
- error: indirection requires pointer operand (‘int’ invalid)
- What is the difference between exit(0) and exit(1) in C?
- What does “%.*s” mean in printf?
- Display value found at given address gdb
- Array definition – Expression must have a constant value
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- strcmp not working
- How to printf a memory address in C
- What is the use of intptr_t?
- error: aggregate value used where an integer was expected
- Removing trailing newline character from fgets() input
- What does “request for member ‘*******’ in something not a structure or union” mean?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- “Multiple definition”, “first defined here” errors
- Invalid type argument of -> C structs
- Does C have a string type?
- how use EOF stdin in C
- Execution of printf() and Segmentation Fault
- How does the strtok function in C work? [duplicate]
- error: function returns address of local variable
- Return a `struct` from a function in C
- C: scanf to array
- What are “prototypes” in a C program?
- Realloc Invalid Pointer in C
- What’s the difference between “mod” and “remainder”?
- undefined reference to `std::ios_base::Init::Init()’
- previous declaration of ‘function’ was here in C [duplicate]
- Difference between the int * i and int** i
- Pointer to 2D arrays in C
- How to Compare 2 Character Arrays [duplicate]
- error: `itoa` was not declared in this scope