I tried something like this:
The main.c
Code:
#include <malloc.h>
#include <stdio.h>
#include "GetLine.h"
int main(void){
char *Input = (char *)malloc(sizeof(char) * 100);
GetLine(Input, 100)
printf("%s\n", Input);
return 0;
}
At the end it gave me these:
Code:
C:\HChingWong\MineSweeper>gcc -o main.exe main.c GetLine.c
GetLine.c: In function 'GetLine':
GetLine.c:2:14: error: 'NULL' undeclared (first use in this function)
GetLine.c:2:14: note: each undeclared identifier is reported only once for each
function it appears in
GetLine.c:9:22: warning: incompatible implicit declaration of built-in function
'strchr'
How can I solve these disgusting things?
And the other things I think are less useful.
The GetLine.h
Code:
int GetLine(char *, int);
And The GetLine.c
Code:
int GetLine(char *Input, const int SizeTag){
if(Input == NULL){
puts("Unallocated input buffer.");
return -1;
}
fgets(Input, SizeTag);
char *LastCharPtr = strchr(Input, '\n');
if(!LastCharPtr != NULL){
puts("Input is too long.\n");
*Input = '\0';
return -1;
}
*LastCharPtr = '\0';
return 0;
}