我必须编写一个程序,每个程序分别读取数字.是否可以只读取文件的一行,然后int从缓冲区中读取,依此类推,直到文件结束?很难找到使用读写的好例子.我的例子是有点工作,但我想阅读,直到它检测到'\n'char然后将缓冲区转换为int.
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
int fd[2];
void readFile(int fd) {
unsigned char buffer[10];
int bytes_read;
int k=0;
do {
bytes_read = read(fd, buffer, 10);
k++;
for(int i=0; i<10; i++) {
printf("%c", buffer[i]);
}
}
while (bytes_read != 0);
}
int tab[50];
int main(int argc, char *argv[]) {
if(argv[1] == NULL || argv[2] == NULL) {
printf("Function requires two arguments!\nGood bye...\n");
return -1;
}
else {
if (access(argv[1], F_OK) == …Run Code Online (Sandbox Code Playgroud)