LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2006, 11:35 AM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
fgetc - segmentation fault


i did a search for fgetc and this is the first link it returned:
http://www.linuxquestions.org/questi...ighlight=fgetc

i am wondering why i seg-fault when argv[1] is a 7 gigabyte file.

this is basically the same as cat-ing everything under ascii 127:
Code:
#include "stdio.h"

main(int argc, char *argv[])
{
 int c;
 FILE * fstream;

 fstream = fopen(argv[1], "r");
 c = fgetc(fstream);

 while(c != EOF)
 {
  if(c >= 0 && c <= 127)
   printf("%c", c);
  c = fgetc(fstream);
 }
 fclose(fstream);
}
 
Old 06-20-2006, 01:03 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Well you're not checking to see if you managed to open the file.
 
Old 06-21-2006, 07:39 AM   #3
ppanyam
Member
 
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
Could it be a >2GB file problem? What are the HW and OS versions?

We still hae apps which dont go beyond 2GB files.
ppanyam
 
Old 06-22-2006, 11:26 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
schneidz@lq:/home/schneidz> uname -a
AIX ecq-cellmgr 2 5 0024yyyyyy00
thanks,
 
Old 06-23-2006, 12:33 AM   #5
ppanyam
Member
 
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
I dont really want to comment on this but since no one has replied, I take liberty to say what I think..

Did you compile with 64 bit option? I think you have to use -n64 switch with cc while compiling. Sorry again, I havent worked on AIX for 4 years now, but recently some of my friends told me their "old programs having 2GB file limitations will work if they are recompiled for 64 bit option." I havent tested it myself.

Best of luck.

ppanyam
 
Old 06-23-2006, 08:50 AM   #6
cigarstub
Member
 
Registered: Sep 2005
Posts: 145

Rep: Reputation: 15
why int argc w/out using? newbie wuestion sorry
 
Old 06-23-2006, 10:58 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
argc tell you the number of command line arguments that were passed in.
argv is a list of the actual arguments that were passed in.
The first argument is always the name of the program.

Hence: ls -l
ls is the name of the program and -l is the first argument:
argv[0] = ls
argv[1] = -l
 
Old 06-23-2006, 01:42 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by ppanyam
I dont really want to comment on this but since no one has replied, I take liberty to say what I think...
thanks, i guess i just assumed the 2 Gig file limitation just applied to windoze.

fyi my stock cap solution was to
Code:
split -b 1000000000 file.txt
it's not romantic and i end up with 12 incomplete lines but not a big deal.
 
Old 06-23-2006, 01:44 PM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by cigarstub
why int argc w/out using? newbie wuestion sorry
i always define my main() with int argc char *argv[] regardless if i am using command line arguements.

might be a waste but oh well.
 
Old 06-28-2006, 02:35 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by ppanyam
I dont really want to comment on this but since no one has replied, I take liberty to say what I think..

Did you compile with 64 bit option? I think you have to use -n64 switch with cc while compiling. Sorry again, I havent worked on AIX for 4 years now, but recently some of my friends told me their "old programs having 2GB file limitations will work if they are recompiled for 64 bit option." I havent tested it myself.

Best of luck.

ppanyam

this is what i got
Code:
schneidz@lq:/home/schneidz> cc -g -n64 file.c -o file.x
cc: 1501-216 command option 64 is not recognized - passed to ld

"file.c", line 47.20: 1506-342 (W) "/*" detected in comment.
ld: 0706-027 The -n flag is ignored.
ld: 0706-012 The -6 flag is not recognized.
ld: 0706-012 The -4 flag is not recognized.
thanks amways

i think its
Code:
 cc -q64
but im not able to test it with a large file. (no output from cc though)

Last edited by schneidz; 06-28-2006 at 02:41 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C, segmentation fault mattp Programming 37 12-16-2007 09:09 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
segmentation fault for everything gsv Linux - Newbie 1 08-23-2004 06:19 PM
segmentation fault sakkie Linux - Security 7 03-26-2004 11:10 PM
segmentation fault venerandrew Linux - Software 2 03-04-2004 07:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration