Thread: hi to over come with core dump

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    hi to over come with core dump

    Code:
    #include<stdio.h>
    main()
    {
    FILE *fp=NULL;
    char ch;
    fp=fopen("/u/n073313/vijay/File.txt","rb");
    while(1)
    {
    ch=fgetc(fp);
    if(ch==EOF)
    break;
    printf("%c",ch);
    }
    fclose(fp);
    }
    its giving o/p with core dump:
    939,MUM,ord,396,2,3.0,4.0
    100,bom,nru,1009,10,4.0,6.0
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿ

    please help me in this.
    thanks&regards
    vijay

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    1) Indent.
    2) Main returns int.
    3) Does fopen fail? If yes, then do not attempt to read from it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    When you compiled, you should have gotten a warning about how ch==EOF can never be true (EOF doesn't fit into a char, must be an int), so you should probably deal with that.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    hi tabstop,
    when i am compiling i am not getting any warnings.
    the o/p i am getting is correct it is reading the file.
    939,MUM,ord,396,2,3.0,4.0
    100,bom,nru,1009,10,4.0,6.0

    but i am getting core only.

  5. #5
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    I don't think that is "core dump".
    They are garbage values or something.

    As tabstop suggested, change char to int type.
    If you have followed that already,perhaps the file didn't end with EOF.
    You may have to enter ctrl+D or ctrl+z at the end of the file depending on the OS.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by stevesmithx View Post
    I don't think that is "core dump".
    They are garbage values or something.

    As tabstop suggested, change char to int type.
    If you have followed that already,perhaps the file didn't end with EOF.
    You may have to enter ctrl+D or ctrl+z at the end of the file depending on the OS.
    No modern OS actually cares about EOF characters. In old days (prior to DOS, such as CP/M, RSX/RSTS-E/RT11 - I'm sure other old OS's had this concept too) filesystems often kept the file-size in number of blocks, and of course, to know where the final block ended, you'd have to have something to indicate that "you have now read everything in this file", and CTRL-Z was often used for this purpose in those systems.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    Thanks alot
    tabstop and all i changed from char to int its working.

  8. #8
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Quote Originally Posted by matsp View Post
    No modern OS actually cares about EOF characters. In old days (prior to DOS, such as CP/M, RSX/RSTS-E/RT11 - I'm sure other old OS's had this concept too) filesystems often kept the file-size in number of blocks, and of course, to know where the final block ended, you'd have to have something to indicate that "you have now read everything in this file", and CTRL-Z was often used for this purpose in those systems.

    --
    Mats
    Thanks for the nice info once again, Mats.

    prior to DOS, such as CP/M, RSX/RSTS-E/RT11
    Never heard of these OSes before.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Some references:
    http://en.wikipedia.org/wiki/CP/M
    http://en.wikipedia.org/wiki/RSX-11
    http://en.wikipedia.org/wiki/RT-11
    http://en.wikipedia.org/wiki/RSTS/E

    I have used CP/M and RSTS/E (which has a subset of RT-11 and RSX-11 emulation as well, so code written for RT-11 or RSX-11 can be used in RSTS/E, as long as it's not doing too much "funny stuff").

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Learn to recognise that EOF cast to a char very frequently ends up looking like ÿ
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird core dump
    By bean66 in forum C++ Programming
    Replies: 5
    Last Post: 04-01-2009, 05:29 PM
  2. having a core dump
    By justins in forum C Programming
    Replies: 6
    Last Post: 05-21-2008, 12:00 PM
  3. STL vector core dump
    By creativeinspira in forum C++ Programming
    Replies: 9
    Last Post: 07-22-2007, 04:49 PM
  4. Core Dump in While()
    By KrepNatas in forum C Programming
    Replies: 5
    Last Post: 05-17-2005, 11:15 AM
  5. core dump
    By kermit in forum Linux Programming
    Replies: 0
    Last Post: 08-03-2004, 06:25 PM