我知道下面的功能:
size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);
Run Code Online (Sandbox Code Playgroud)
它只能逐字节读取,我的目标是能够一次读取12位然后将它们放入一个数组中.任何帮助或指针将不胜感激!
任何人都可以向我解释我在这里不明白的地方吗?
我试图将参数作为"字符串"传递(我知道c中没有字符串),以便我可以稍后使用该字符串与其他函数一样,例如它必须传递的文件名.但我不知道它为什么不接受它或它应该是什么类型
#include <stdio.h>
int main ( int argc, char *argv[] )
{
char *array= argv[0];
foo(*array);
}
void foo( char *array)
// notice the return type - it's a pointer
{
printf(array);
}
Run Code Online (Sandbox Code Playgroud)
非常感谢!
这段代码的目标是运行四个线程,这将打开四个文本文件,从中读取单词,然后将它们放入一个字符串数组中,
我知道的主要问题:
1-我没有将并发函数放在 void run 函数中,我希望能够将参数传递给该函数
2-我不确定我是否正在修改字符串的全局数组
首先是主要方法:
public static void main(String[] args) throws IOException
{
//declare the threads
Thread thread1 = new Thread(ReadFile("list1.txt", Global.array1,"thread1"));
Thread thread2 = new Thread(ReadFile("list2.txt", Global.array2,"thread2"));
Thread thread3 = new Thread(ReadFile("list3.txt", Global.array3,"thread1"));
Thread thread4 = new Thread(ReadFile("list4.txt", Global.array4,"thread2"));
/*error message from netbeans: cannot find symbol
symbol: method ReadFile(java.lang.String,java.lang.String[])
it says it for every delcaration of the thread*/
thread1.start(); //putting the threads to work
thread2.start();
thread3.start();
thread4.start();
thread1.join(); //telling the threads to finish their work
thread2.join(); …Run Code Online (Sandbox Code Playgroud)