edit: solved
Some background. I've been programming a few years and am generally quite good at thinking in programming terms. I've done C (ansi), java, haskell, and a lot of VHDL recently. I am, however, somewhat rusty on my C so while I understand it fairly well there is always the chance of a stupid blind error.
Currently I am (you have permission to shoot me) using visual studio and the microsoft compiler, simply because a previous program i wrote used 3rd party DLLs that were only compatible with the microsoft compiler. I have no intention of keeping multiple compilers on the same computer so I intend to get used to what is unfortunately the standard now.
The section of code I'm having trouble with is one that should be simple. I've already cleaned up the usual typos and obvious mistakes. The function is just a quick throwtogether for parsing a file into lines (partly as a utility, partly to convert my head from vhdl to C again ready for the rest of the program).
Here is the first half of the program containing the faulty function:
Code:
/*
* Util.c
* Version 1.0
* misc useful functions
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
typedef struct A {
char* line;
struct A* next;
} strlink;
/* reads a file into lines, max length 200 char */
char** parseLines( char* filename )
{
FILE* stream = NULL;
char c = 0;
char* temp = NULL;
char** out = NULL;
strlink* start = NULL;
strlink* cur = NULL;
int i = 0;
int j = 0;
stream = fopen( filename, "r");
if( !stream )
return NULL;
start = calloc( 1, sizeof( strlink ));
cur = start;
/*all is initialised, now parse it into links in a linked list */
do while( c != EOF )
{
temp = calloc( 200, sizeof( char ));
j = 0;
c = fgetc(stream);
while( j < 200 && c != '\n' && c != EOF)
{
temp[j++] = c;
c = fgetc(stream);
}
cur->line = temp;
cur->next = calloc( 1, sizeof( strlink ));
cur = cur->next;
i++;
}
/* build output array from linked list, output is null terminated */
out = calloc( i+1, sizeof ( char* ));
cur = start;
for( j = 0 ; j < i ; j++ )
{
out[j] = cur->line;
start -> cur;
cur = cur->next;
free(start);
}
fclose( stream );
return out;
}
the compiler output, ive got a quick batch i use to remember the tags for me: these have worked fine for me in the past
>cl quests.c util.c /link /OUT:quest.exe
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
quests.c
util.c
util.c(52) : error C2061: syntax error : identifier 'out'
Generating Code...
line 52 is the line
Code:
out = calloc( i+1, sizeof ( char* ))
;
since out is a char**, the allocation is an array of strings, and the brackets line up I'm running out of possible causes. Any insight would be greatly appreciated