added functionality to read file

This commit is contained in:
Rory Healy 2021-08-23 14:29:41 +10:00
parent 47470ba552
commit 69dd495ac0
3 changed files with 21 additions and 51 deletions

View file

@ -1,34 +0,0 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
},
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/gcc",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"cStandard": "c17"
}
],
"version": 4
}

View file

@ -24,21 +24,7 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
char *buffer;
size_t bufsize = 32;
size_t characters;
buffer = (char *)malloc(bufsize * sizeof(char));
if( buffer == NULL)
{
perror("Unable to allocate buffer");
exit(1);
}
printf("Type something: ");
characters = getline(&buffer,&bufsize,stdin);
printf("%zu characters were read.\n",characters);
printf("You typed: '%s'\n",buffer);
readWatchtowers(watchtowers, dataset);
// Cleaning up data
free(watchtowers);
@ -75,6 +61,24 @@ FILE **polygonFile, FILE **outputFile) {
}
void readWatchtowers(watchtower_t *watchtowers, FILE* datasetFile) {
int numTowers = 1;
char *lineBuffer;
int lineCount = 0;
size_t lineBufferSize = 512;
size_t numberCharsRead;
lineBuffer = (char *) malloc(lineBufferSize * sizeof(char));
if (lineBuffer == NULL) {
fprintf(stderr, MALLOC_ERROR);
exit(EXIT_FAILURE);
}
numberCharsRead = getline(&lineBuffer, &lineBufferSize, datasetFile);
while (numberCharsRead > 0) {
lineCount += 1;
printf("line[%06d]: chars=%06zd, buf size=%06zu, contents: %s",\
lineCount, numberCharsRead, lineBufferSize, lineBuffer);
numberCharsRead = getline(&lineBuffer, &lineBufferSize, datasetFile);
}
free(lineBuffer);
lineBuffer = NULL;
}

BIN
voronoi1 Normal file → Executable file

Binary file not shown.