1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Rep Power

    How to store it after comparing ? I tried but its not storing in file.

    Write a program which takes 10 integer numbers from user. Save all the positive numbers to one file, all the negative numbersto another file.

    In this , I know after comparing numbers ,based on comparison condition ,we have to store it in respective positive and negative file.

    I created 2 pointers for this 2 files.
    I did the comparison part and as per the comparison inside it:

    the syntax I used to create file is :
    The file is being created but after that I am not able to do the storing part.
    To store I used this syntax:

    Can somebody guide me?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    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
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    You'd do better with


    Please read the manual about putc. See if you can figure out why it didn't work.

    [edit---> bad code cited in following message removed Sorry that this wrecks the thread but on the other hand, bad code in the thread is also bad.]
    Last edited by b49P23TIvg; September 28th, 2012 at 12:53 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Rep Power
    Originally Posted by b49P23TIvg
    You'd do better with

    if (1 != fprintf(fp1,"%d ",a[i]))
    fputs("\nYour computer is hosed.\n",stderr);
    fprintf() returns the number of characters printed. Your format string has 2 directives. The first directive ("%d") causes at least 1 character to be printed; the second directive (" ") causes exactly 1 character to be written; so, barring output errors, the total number of characters written is 2 or more ... and that is the return value of the function.

    You're testing if it's different than 1. Barring output errors it is guaranteed to be different and the output of your code is to always print "\nYou computer is hosed.\n" to the standard error stream.

    Comments on this post

    • b49P23TIvg agrees : whoops!

IMN logo majestic logo threadwatch logo seochat tools logo