LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   fgetc - segmentation fault (https://www.linuxquestions.org/questions/programming-9/fgetc-segmentation-fault-456595/)

schneidz 06-20-2006 11:35 AM

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);
}


graemef 06-20-2006 01:03 PM

Well you're not checking to see if you managed to open the file.

ppanyam 06-21-2006 07:39 AM

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

schneidz 06-22-2006 11:26 AM

Code:

schneidz@lq:/home/schneidz> uname -a
AIX ecq-cellmgr 2 5 0024yyyyyy00

thanks,

ppanyam 06-23-2006 12:33 AM

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

cigarstub 06-23-2006 08:50 AM

why int argc w/out using? newbie wuestion sorry

graemef 06-23-2006 10:58 AM

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

schneidz 06-23-2006 01:42 PM

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.

schneidz 06-23-2006 01:44 PM

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.

schneidz 06-28-2006 02:35 PM

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)


All times are GMT -5. The time now is 05:07 PM.