Sponsored Content
Top Forums Programming problem in reading file using fread Post 302094645 by odys on Monday 30th of October 2006 07:02:31 PM
Old 10-30-2006
Quote:
Originally Posted by jim mcnamara
sizeof(a pointer to something) = size of a pointer variable, = 4 on a 32 bit machine.
sizeof(buf) is likely 4, not 1000.
char *buf;
sizeof(buf) => 4

char buf[2000];
sizeof(buf) => 2000

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help me ...problem in reading a file

hi, while reading a file line by line # name of the script is scriptrd while read line do echo $line done while executing bash$ ./scriptrd if i give the input as * the output is like it displays the contents of the current directory i jus wanted it to print as * (6 Replies)
Discussion started by: brkavi_in
6 Replies

2. Shell Programming and Scripting

problem in reading a file

i need to read record by record i use script #!/bin/ksh for i in 'cat filename' do echo $1 done but i dont get expected result i just get filename echoed on screen (4 Replies)
Discussion started by: er_zeeshan05
4 Replies

3. UNIX for Dummies Questions & Answers

Intermittent problem reading from an input file.

First of all thanks to all for the good post, and the great site. I'm a noob, but I've been able to learna a lot by checking past posts. I haven't been able to make sense of a problem that I've been working on for a while, hopefully someone can help me out. The script I wrote telnets into... (7 Replies)
Discussion started by: Wallygooo32
7 Replies

4. Shell Programming and Scripting

problem in reading a record from the file

Hi Guys, I need to check whether the last column is RP, If so, then i have to second column and pass it to a select statement as sonid and fetch the value to a variable and run it. This has to be done till the last column is RW. value Fatherid sonid topid ... (8 Replies)
Discussion started by: mac4rfree
8 Replies

5. Shell Programming and Scripting

Problem with reading from a properties file

Hi, i have a properties file a.prop where entry is like PROCESS_IDX=0 Now in my shell schript i am doing like this. #!/bin/sh . a.prop .............. -....................... while read line do # tokenize the string by ",". var=(`echo $line | tr ',' ' '`) echo $PROCESS_IDX -->... (6 Replies)
Discussion started by: sailaja_80
6 Replies

6. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

7. Shell Programming and Scripting

Problem in reading a file

Hi Guys, I am having a file which does not have any name when i do a ls -l -rw-r--r-- 1 dctrdat1 dctrdata 35 Feb 09 08:04 -rw-r--r-- 1 dctrdat1 dctrdata 11961 Feb 08 06:40 DAI_data.txt Now i want to see what is inside that file. Can you please let me know how to read... (9 Replies)
Discussion started by: mac4rfree
9 Replies

8. Shell Programming and Scripting

Problem in reading file (bash)

i get a name from user first name : last name, in this format. Now i am saving this to a file. what i want is, I do not want to save any name if I already have one entry o that same name..what should i do for example user give robert fernandez this will save in file as robert:fernandez. if... (5 Replies)
Discussion started by: Learnerabc
5 Replies

9. Shell Programming and Scripting

Problem reading file in while/read loop

I know I should be able to see a way of doing this easily, but my brain just won't engage. I have a script working on an embedded device that checks to see if an item is in a blacklist before performing some actions. At the moment the code reads thus.... while read BLACKLIST ; do ... (7 Replies)
Discussion started by: Bashingaway
7 Replies

10. Programming

Malloc problem with fread() to read file to structure in C

Hello, I am trying to read a text file into linked list, but always got the first and last records wrong. 1) The problem looks related to the initialization of the node temp with malloc(), but could not figure it out. No error/warning at compiling, though. 2) The output file is empty,... (10 Replies)
Discussion started by: yifangt
10 Replies
msgsnap(2)							   System Calls 							msgsnap(2)

NAME
msgsnap - message queue snapshot operation SYNOPSIS
#include <sys/msg.h> msgsnap(int msqid, void *buf, size_t bufsz, long msgtyp); DESCRIPTION
The msgsnap() function reads all of the messages of type msgtyp from the queue associated with the message queue identifier specified by msqid and places them in the user-defined buffer pointed to by buf. The buf argument points to a user-defined buffer that on return will contain first a buffer header structure: struct msgsnap_head { size_t msgsnap_size; /* bytes used/required in the buffer */ size_t msgsnap_nmsg; /* number of messages in the buffer */ }; followed by msgsnap_nmsg messages, each of which starts with a message header: struct msgsnap_mhead { size_t msgsnap_mlen; /* number of bytes in the message */ long msgsnap_mtype; /* message type */ }; and followed by msgsnap_mlen bytes containing the message contents. Each subsequent message header is located at the first byte following the previous message contents, rounded up to a sizeof(size_t) bound- ary. The bufsz argument specifies the size of buf in bytes. If bufsz is less than sizeof(msgsnap_head), msgsnap() fails with EINVAL. If bufsz is insufficient to contain all of the requested messages, msgsnap() succeeds but returns with msgsnap_nmsg set to 0 and with msgsnap_size set to the required size of the buffer in bytes. The msgtyp argument specifies the types of messages requested as follows: o If msgtyp is 0, all of the messages on the queue are read. o If msgtyp is greater than 0, all messages of type msgtyp are read. o If msgtyp is less than 0, all messages with type less than or equal to the absolute value of msgtyp are read. The msgsnap() function is a non-destructive operation. Upon completion, no changes are made to the data structures associated with msqid. RETURN VALUES
Upon successful completion, msgsnap() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The msgsnap() function will fail if: EACCES Operation permission is denied to the calling process. See Intro(2). EINVAL The msqid argument is not a valid message queue identifier or the value of bufsz is less than sizeof(struct msgsnap_head). EFAULT The buf argument points to an illegal address. USAGE
The msgsnap() function returns a snapshot of messages on a message queue at one point in time. The queue contents can change immediately following return from msgsnap(). EXAMPLES
Example 1 msgsnap() example This is sample C code indicating how to use the msgsnap function (see msgids(2)). void process_msgid(int msqid) { size_t bufsize; struct msgsnap_head *buf; struct msgsnap_mhead *mhead; int i; /* allocate a minimum-size buffer */ buf = malloc(bufsize = sizeof(struct msgsnap_head)); /* read all of the messages from the queue */ for (;;) { if (msgsnap(msqid, buf, bufsize, 0) != 0) { perror("msgsnap"); free(buf); return; } if (bufsize >= buf->msgsnap_size) /* we got them all */ break; /* we need a bigger buffer */ buf = realloc(buf, bufsize = buf->msgsnap_size); } /* process each message in the queue (there may be none) */ mhead = (struct msgsnap_mhead *)(buf + 1); /* first message */ for (i = 0; i < buf->msgsnap_nmsg; i++) { size_t mlen = mhead->msgsnap_mlen; /* process the message contents */ process_message(mhead->msgsnap_mtype, (char *)(mhead+1), mlen); /* advance to the next message header */ mhead = (struct msgsnap_mhead *) ((char *)mhead + sizeof(struct msgsnap_mhead) + ((mlen + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1))); } free(buf); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
ipcrm(1), ipcs(1), Intro(2), msgctl(2), msgget(2), msgids(2), msgrcv(2), msgsnd(2), attributes(5) SunOS 5.11 8 Mar 2000 msgsnap(2)
All times are GMT -4. The time now is 09:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy