[英]int main(int argc, const char * argv[]) AND file input
I've never used,我没用过,
int main(int argc, const char * argv[])
int main(int argc, const char * argv[])
For most programs, I usually just compile in terminal (using mac) using two separate C files, example…对于大多数程序,我通常只是使用两个单独的 C 文件在终端(使用 mac)中编译,例如……
gcc functions.c main.c
gcc 函数.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.但是现在我需要使用 int main(int argc, const char * argv[]) ......我只是不知道我是否正确使用它。 Heres some code…
继承人一些代码...
I compile in the command line doing…我在命令行中编译...
gcc main.c input.txt
gcc main.c input.txt
terminal tells me…终端告诉我……
ld: file too small for architecture x86_64
ld:对于架构 x86_64 文件太小
collect2: ld returned 1 exit status
collect2: ld 返回 1 个退出状态
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.注意我的函数可以工作(我在不使用文件输入的情况下进行了测试)并且也在 main.c 中......我只是没有在这篇文章中包含它们。 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.
我要做的就是将其读入我的程序并打印出来,以验证我是否正确读取了我的输入。
This is not like a perl script or shell script, where you run这不像你运行的 perl 脚本或 shell 脚本
perl main.pl input.txt
With a compiled language like C, you first compile the program into an executable使用像 C 这样的编译语言,您首先将程序编译为可执行文件
gcc main.c -o myprogram
and then run the executable with the input file然后使用输入文件运行可执行文件
./myprogram input.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.