low-level-io

Writing data read with read () to int array in C

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 11:33:46
问题 I have a file with numbers on each line. I am trying to write the data read from the file to the int array with the read () function. I can read the file and print it to the terminal. How can i get the numbers i read into arr array ? Here is my code #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> int main() { int len, fd,arr[10000],i=0; fd = open("1.txt", O_RDONLY); if (fd >= 0) { while(read(fd, &len, sizeof(int)) > 0){ write(1, &len, sizeof

What is causing my program to hang and not exit properly? (pipe, read system call, while loop)

こ雲淡風輕ζ 提交于 2021-01-27 11:22:49
问题 I have a program where I write from several child processes to a pipe, and then attempt to read all the messages written to each process, from each pipe, and print them to the screen. With the following code (specifically, the while loop using the read system call to store the messages into buffer buf ), my program will hang and not exit, nor print all of the messages sent to the different processes. for (i = 0; i < MAXP; i++) { if(id == i) { while(read(pfds[i][0], buf, sizeof(buf)) > 0)

What is causing my program to hang and not exit properly? (pipe, read system call, while loop)

ぃ、小莉子 提交于 2021-01-27 11:22:48
问题 I have a program where I write from several child processes to a pipe, and then attempt to read all the messages written to each process, from each pipe, and print them to the screen. With the following code (specifically, the while loop using the read system call to store the messages into buffer buf ), my program will hang and not exit, nor print all of the messages sent to the different processes. for (i = 0; i < MAXP; i++) { if(id == i) { while(read(pfds[i][0], buf, sizeof(buf)) > 0)

Service Calls Executing Based on User Input

折月煮酒 提交于 2019-12-25 04:26:32
问题 I've just written my first MIPS addition program. My output is expected ($t0 + $t1 = $t2), but I have a question regarding some strange behavior that I believe should be avoidable. On the lines where I gather the user input ( li $v0, 5 ), the value of the $v0 service call gets set to the value of my user input. So for example, if I enter "10" as user input, $v0 is assigned the value 10, which is the service code to terminate the program. Is there something I can do to ensure that my user

Very Simple Crypt Program Error

雨燕双飞 提交于 2019-12-25 03:13:04
问题 I'm creating a program that takes a file as input & outputs the decrypted password of each line. The file contains three lines of encrypted passwords. I am guaranteed that the passwords decrypt to 4 letter words. Given that i have created an char[] of the letters. I'm having a problem reading the file line by line using LOW LEVEL IO and putting the resulting password in a new file. Any & all advice is appreciated! Here is my code so far: #include <sys/types.h> #include <sys/stat.h> #include

How to properly error trap read in c to get byte number from a file descriptor

若如初见. 提交于 2019-12-12 03:57:17
问题 I am currently writing a small dummy program to try and get the hang of properly using the read in c. I made a small function called readdata to read from the file descriptor and store in a buffer then return the number of bytes read. My problem is I am trying to correctly error handle and trap things so that there is no buffer overflow but I keep doing something from. Here is the tester: #include <stdio.h> #include <string.h> #include <unistd.h> #define BUFSIZE 10 int readdata(int fd, char

Will my program return the correct position I wanted after meeting a set number of newlines?

半城伤御伤魂 提交于 2019-12-11 16:01:10
问题 I'm trying to read a file backwards (say 10 lines at the end of the file). I would increment my new line counter ( newline_counter ) everytime it reads a '\n'. Once newline_counter reaches user_num (argument), say 10 lines, lseek() would stop at the current position ( current_pos ). I'm returning this position so that I can use this position in another function which uses lseek() to this position and start reading from this position and write until the end of the file. I have successfully

Altering text in a .txt file and creating a new file output in MATLAB

非 Y 不嫁゛ 提交于 2019-12-11 02:44:30
问题 I apologize in advance if the title seems a bit off. I was having trouble deciding what exactly I should name it. Anyway, basically what I am doing now is completely homework that deals with low-level I/Os. For my one assignment, I have given two .txt files, one that includes a list of email addresses and another that includes a list members who no longer was to be on an email list. What I have to do is delete the emails of the members from the second list. Additionally, there may be some

How to read individual sectors/clusters using DeviceIoControl() in Windows?

倖福魔咒の 提交于 2019-12-06 09:33:56
问题 I dropped my laptop while Windows was preparing to hibernate and as a result, I got a head crash on the hard drive. (Teaches me to get a hard drive and/or laptop with a freefall sensor next time around.) Anyway, running SpinRite to try to recover the data has resulted in all the spare sectors on the disk to all be all used up for all the recoverable sectors so far. SpinRite is still going right now, but since there won't be anymore spare sectors to be used, I think it'll be a fruitless

How to read individual sectors/clusters using DeviceIoControl() in Windows?

廉价感情. 提交于 2019-12-04 16:51:31
I dropped my laptop while Windows was preparing to hibernate and as a result, I got a head crash on the hard drive. (Teaches me to get a hard drive and/or laptop with a freefall sensor next time around.) Anyway, running SpinRite to try to recover the data has resulted in all the spare sectors on the disk to all be all used up for all the recoverable sectors so far. SpinRite is still going right now, but since there won't be anymore spare sectors to be used, I think it'll be a fruitless exercise except to tell me where all the bad sectors are. Anyway, I'm planning on writing an application to