Sponsored Content
Top Forums Programming Segmentation fault in fopen when in write mode. Post 302672711 by shoaibjameel123 on Monday 16th of July 2012 10:12:30 PM
Old 07-16-2012
I would agree with Corona688. I could not express this very well in my reply. My objective is to keep the values to 32bit ints only.

Alister has got the fundamentals right. yes, int32_t is typedef'ed to int. But I also recall that if on a 32bit architecture, one has to use a 64bit int, then one needs to explicitly specify int64_t.

---------- Post updated at 10:12 AM ---------- Previous update was at 09:48 AM ----------

I did try to run the code with the line:
Code:
printf("file_name reference on line %d = %p\n", __LINE__, file_name);

I get this as outputs,which makes me feel that file_name is not getting corrupted. Here is the result when I execute the code:

Code:
file_name reference on line 88 = (nil)
file_name reference on line 140 = 0x1d6ed830
file_name reference on line 305 = 0x1d6ed830
file_name reference on line 202 = 0x1d6ed830
file_name reference on line 206 = 0x1d6ed830
file_name reference on line 276 = 0x1d6ed830
file_name reference on line 209 = 0x1d6ed830
Segmentation fault (core dumped)

I even tested with this but still the program fails to execute:

Code:
output_pointer = fopen ( "1.dat" , "w" );

 

10 More Discussions You Might Find Interesting

1. Programming

segmentation fault

sometimes for this code i get a segmentation fault for codes llike this : int main{ int * a= 0; int b; a = (int*)malloc(sizeof(int)); ///some code using these variable but no freeing of a if(a){ free(a); a = 0; } return... (3 Replies)
Discussion started by: wojtyla
3 Replies

2. Programming

Hi! segmentation fault

I have written a program which takes a directory as command line arguments and displays all the dir and files in it. I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
Discussion started by: vijlak
4 Replies

3. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

4. Programming

segmentation fault

Hi, I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Discussion started by: mind@work
3 Replies

5. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

6. UNIX for Dummies Questions & Answers

Segmentation fault

#include<stdio.h> #include<malloc.h> #include<unistd.h> #include<stdlib.h> void *start_1(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); pthread_exit((void*)1); } void *start_2(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); return (void*)2; }... (2 Replies)
Discussion started by: vincent__tse
2 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

9. Shell Programming and Scripting

Count Segmentation fault and write to the file

Hi everyone Need to get version of npm application that have several output like this: root: nmp -version 10 root: nmp -version 10 root: nmp-new -version 3.1 root: nmp-old -version Segmentation fault count them , after that write to the file like this: 10 2 3.1 1 (1 Reply)
Discussion started by: indeed_1
1 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
Mail::Mbox::MessageParser::MetaInfo(3pm)		User Contributed Perl Documentation		  Mail::Mbox::MessageParser::MetaInfo(3pm)

NAME
Mail::Mbox::MessageParser::MetaInfo - A cache for folder metadata DESCRIPTION
This module implements a cache for meta-information for mbox folders. The information includes such items such as the file position, the line number, and the byte offset of the start of each email. METHODS AND FUNCTIONS SETUP_CACHE(...) SETUP_CACHE( { 'file_name' => <cache file name> } ); <cache file name> - the file name of the cache Call this function once to set up the cache before creating any parsers. You must provide the location to the cache file. There is no default value. Returns an error string or 1 if there is no error. CLEAR_CACHE(); Use this function to clear the cache and delete the cache file. Normally you should not need to clear the cache--the module will automatically update the cache when the mailbox changes. Call this function after SETUP_CACHE. WRITE_CACHE(); Use this function to force the module to write the in-memory cache information to the cache file. Normally you do not need to do this--the module will automatically write the information when the program exits. $ref = new( { 'file_name' => <mailbox file name>, 'file_handle' => <mailbox file handle>, }); <file_name> - The full filename of the mailbox <file_handle> - An opened file handle for the mailbox The constructor for the class takes two parameters. file_name is the filename of the mailbox. This will be used as the cache key, so it's important that it fully defines the path to the mailbox. The file_handle argument is the opened file handle to the mailbox. Both arguments are required. Returns a reference to a Mail::Mbox::MessageParser object, or a string describing the error. BUGS
No known bugs. Contact david@coppit.org for bug reports and suggestions. AUTHOR
David Coppit <david@coppit.org>. LICENSE
This software is distributed under the terms of the GPL. See the file "LICENSE" for more information. HISTORY
This code was originally part of the grepmail distribution. See http://grepmail.sf.net/ for previous versions of grepmail which included early versions of this code. SEE ALSO
Mail::Mbox::MessageParser perl v5.10.1 2010-06-06 Mail::Mbox::MessageParser::MetaInfo(3pm)
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy