I've never used,
int main(int argc, const char * argv[])
For most programs, I usually just compile in terminal (using mac) using two separate C files, example…
gcc functions.c main.c
But now I need to use int main(int argc, const char * argv[])… I just don't know if I'm using it correctly. Heres some code…
I compile in the command line doing…
gcc main.c input.txt
terminal tells me…
ld: file too small for architecture x86_64
collect2: ld returned 1 exit status
NOTE my functions work (i tested without using file input) and are in main.c also… i just didn't include them in this post. Also, node is just a basic node struct to a linked list.
int main(int argc, const char * argv[])
{
FILE *input;
input = fopen(argv[1], "r");
node *list = malloc(sizeof(node));
char *string = malloc(sizeof(char)*1023);
fscanf(input, "%s", string);
//convert a string to linked list
list= sTol(string);
//print the linked list
printList(list);
return 0;
} // end main()
Am i completely wrong? the input simply contains one line that says 'hello'. All I'm trying to do is read that into my program and print it just to verify I'm reading my input correctly.
Best Answer
This is not like a perl script or shell script, where you run
With a compiled language like C, you first compile the program into an executable
and then run the executable with the input file