Sponsored Content
Full Discussion: Passing pointers to struct
Homework and Emergencies Homework & Coursework Questions Passing pointers to struct Post 302486469 by m.d.ludwig on Saturday 8th of January 2011 07:59:14 PM
Old 01-08-2011
The size of a void is 1, so only 1 byte is getting written. You need to provide the size of the structure, either:
Code:
int bwrite(unsigned int bloque, void *buf, size_t siz){
    lseek(mifd, bloque*tbloque, SEEK_SET);
    return write(mifd, buf, siz);
}

or
Code:
 int bwrite(unsigned int bloque, struct superbloque  *buf){
     lseek(mifd, bloque*tbloque, SEEK_SET);
     return write(mifd, buf, sizeof(*buf));
 }


Last edited by m.d.ludwig; 01-08-2011 at 08:59 PM.. Reason: superfluous word
 

10 More Discussions You Might Find Interesting

1. Programming

Need a simple example of passing FILE pointers

Dear friends, can anybody pls tell me how to pass FILE pointer in c. I am so confused .. :confused: suppose I ve two function 1. file_open() 2. read_line() I want to call these function from main() function and in file_open() function it will open that file and in read_line()... (5 Replies)
Discussion started by: user_prady
5 Replies

2. Programming

Pointer to a struct (with pointers) *** glibc detected *** double free

I am using a structure defined as follows struct gene_square { double *x; double *y; };I have class, with a member function which is a pointer of this type: gene_square* m_Genes;I am allocating memory in the constructors like this: m_Genes = new gene_square; for (ii=0;... (1 Reply)
Discussion started by: jatoo
1 Replies

3. UNIX for Advanced & Expert Users

Passing socket struct between kernel threads - module programming

I write kernel module with kernel threads using linux/kthread.h on 2.6.* kernel I tried to passing data between two kernel threads with data argument of kthread_run( fun, data , NAME ); but this is not work I dont know why. I tried many possibility and nothing works. So I thought that... (0 Replies)
Discussion started by: marcintom
0 Replies

4. Homework & Coursework Questions

C++ struct pointers & functions

Hi All, My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible... (0 Replies)
Discussion started by: pondlife
0 Replies

5. UNIX for Dummies Questions & Answers

Passing struct through unix pipe -solved

EDIT: Nevermind, called a friend who is good at this stuff and he figured it out :D Hi all, So I'm trying to teach myself to write programs for unix in c. I am currently creating a program, and I need to pass a struct through a pipe, but I can't figure out how. The struct I want to pass... (0 Replies)
Discussion started by: twnsfn34
0 Replies

6. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

7. Programming

Passing an instance of struct to functions in other src files

I am trying to work out the best syntax for a relatively simple operation. The goal is to declare an instance of a struct and pass it around to be populated and have the data manipulated. There is an extra wrinkle in that the functions are in different src files. The main is simple, #include... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

8. Programming

Using pointers to struct members as args to functions

In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf. Anyway, here's a... (5 Replies)
Discussion started by: uiop44
5 Replies

9. Programming

Passing Pointers by reference in C++ Problem

Hello All, I am having this issue...where I am actually having hard time understanding the problem: The code is as follows: #include<iostream.h> void fxn(char*** var) { int i =4; *var = (char**)malloc(i*sizeof(char*)); for(int j =0; j<4; j++) { *var = "name"; cout<<*var;... (6 Replies)
Discussion started by: mind@work
6 Replies

10. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies
PREAD(2)						     Linux Programmer's Manual							  PREAD(2)

NAME
pread, pwrite - read from or write to a file descriptor at a given offset SYNOPSIS
#define _XOPEN_SOURCE 500 #include <unistd.h> ssize_t pread(int fd, void *buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); DESCRIPTION
pread() reads up to count bytes from file descriptor fd at offset offset (from the start of the file) into the buffer starting at buf. The file offset is not changed. pwrite() writes up to count bytes from the buffer starting at buf to the file descriptor fd at offset offset. The file offset is not changed. The file referenced by fd must be capable of seeking. RETURN VALUE
On success, the number of bytes read or written is returned (zero indicates that nothing was written, in the case of pwrite, or end of file, in the case of pread), or -1 on error, in which case errno is set to indicate the error. ERRORS
pread can fail and set errno to any error specified for read(2) or lseek(2). pwrite can fail and set errno to any error specified for write(2) or lseek(2). CONFORMING TO
Unix98 HISTORY
The pread and pwrite system calls were added to Linux in version 2.1.60; the entries in the i386 system call table were added in 2.1.69. The libc support (including emulation on older kernels without the system calls) was added in glibc 2.1. SEE ALSO
read(2), write(2), lseek(2) Linux 2.2.0-pre9 1999-01-21 PREAD(2)
All times are GMT -4. The time now is 01:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy