( y / n ) : "); scanf("\n"); scanf("%c",&another); } while (another=='y'); return 0; } input_record(rec) struct name *rec; { printf("\nEnter int___member1: "); scanf("%4d",&(*rec).int___member1); printf("\nEnter float_member2: "); scanf("%f",&(*rec).float_member2); printf("\nEnter char__member3: "); scanf("\n"); scanf("%c",&(*rec).char__member3); } [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <67b58bba.0401011548.611de286@posting.google.com> [ref] => [htmlstate] => on_nl2br [postusername] => hpy_awad@yahoo.com [ip] => hpy_awad@yahoo. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> ( y / n ) : "); >scanf("\n"); >scanf("%c",&another); >} while (another=='y'); >return 0; >} >input_record(rec) >struct name *rec;[/ref] Why are you still using this obsolete style for a function definition? [ref] >{ >printf("\nEnter int___member1: "); >scanf("%4d",&(*rec).int___member1);[/ref] The -> operator is much preferred over the convoluted dereference syntax you have: scanf("%4d",&rec->int___member1); [ref] >printf("\nEnter float_member2: "); >scanf("%f",&(*rec).float_member2); >printf("\nEnter char__member3: "); >scanf("\n"); >scanf("%c",&(*rec).char__member3); >}[/ref] <> [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <67b58bba.0401011548.611de286@posting.google.com> [htmlstate] => on_nl2br [postusername] => Barry [ip] => schwarzb@deloz. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> formatting float variables to fprintf function - UNIX Programming

formatting float variables to fprintf function - UNIX Programming

formatting float variables to fprintf has error to my writing to output file called rental and I do not the reason that a rabish is written to the file instead of the actual input screen values ? #include <stdio.h> //part09_le01_file_processing_file_setup_ver_01_iti_ r01_ch09.c struct name { int int___member1; float float_member2; char char__member3; }; main() { struct name record; FILE *fpointer; fpointer=fopen("rental","w"); char another; do { input_record(&record); fprintf(fpointer,"%4d %f %c\n",record); printf (" \nADD ANOTHER RECORD ----> ( y / n ) : "); scanf("\n"); scanf("%c",&another); } while (another=='y'); return 0; } input_record(rec) struct name *rec; { printf("\nEnter int___member1: "); scanf("%4d",&(*rec).int___member1); printf("\nEnter float_member2: "); ...

  1. #1

    Default formatting float variables to fprintf function

    formatting float variables to fprintf has error to my writing to
    output file called rental and I do not the reason that a rabish is
    written to the file instead of the actual input screen values ?

    #include <stdio.h>
    //part09_le01_file_processing_file_setup_ver_01_iti_ r01_ch09.c
    struct name {
    int int___member1;
    float float_member2;
    char char__member3;
    };
    main()
    {
    struct name record;
    FILE *fpointer;
    fpointer=fopen("rental","w");
    char another;

    do {
    input_record(&record);
    fprintf(fpointer,"%4d %f %c\n",record);
    printf (" \nADD ANOTHER RECORD ----> ( y / n ) : ");
    scanf("\n");
    scanf("%c",&another);
    } while (another=='y');
    return 0;
    }
    input_record(rec)
    struct name *rec;
    {
    printf("\nEnter int___member1: ");
    scanf("%4d",&(*rec).int___member1);
    printf("\nEnter float_member2: ");
    scanf("%f",&(*rec).float_member2);
    printf("\nEnter char__member3: ");
    scanf("\n");
    scanf("%c",&(*rec).char__member3);
    }
    hpy_awad@yahoo.com Guest

  2. #2

    Default Re: formatting float variables to fprintf function

    com (com) writes in comp.unix.solaris:
    |struct name {
    |int int___member1;
    |float float_member2;
    |char char__member3;
    |};
    |fprintf(fpointer,"%4d %f %c\n",record);

    You only provide one argument to fprintf, but ask it to print 3 things,
    so it just makes up random garbage for the values of the second and
    third. You must specify a value for every %-specifier - you can't just
    put the struct there - you need to do:
    fprintf(fpointer,"%4d %f %c\n", record.int___member1,
    record.float_member2, record.char__member3);

    --
    __________________________________________________ ______________________
    Alan Coopersmith calberkeley.org
    http://www.CSUA.Berkeley.EDU/~alanc/ aka: COM
    Working for, but definitely not speaking for, Sun Microsystems, Inc.
    Alan Guest

  3. #3

    Default Re: formatting float variables to fprintf function

    On 1 Jan 2004 15:48:14 -0800, com (com)
    wrote:
     

    Learn to indent. It will save you a lot of trouble later.
     

    There is no prototype in scope for input_record.
     

    Here is your problem. fprintf will not dive into your structure to
    retrieve the members. You must do it yourself with something like
    fprintf(fpointer, "%4d %f %c\n",
    record.int___member1,
    record.float_member2
    record.char__member3);
     

    Why are you still using this obsolete style for a function definition?
     

    The -> operator is much preferred over the convoluted dereference
    syntax you have:
    scanf("%4d",&rec->int___member1);
     



    <<Remove the del for email>>
    Barry Guest

Similar Threads

  1. Apparent bug in Win32::API if function returns a float or a double
    By trevors_decoy@hotmail.com in forum PERL Modules
    Replies: 4
    Last Post: May 23rd, 09:09 AM
  2. Replies: 0
    Last Post: October 21st, 03:58 PM
  3. #25936 [NEW]: comparing 2 float variables with same value result false
    By sebastian dot sieburg at partyleader dot de in forum PHP Development
    Replies: 0
    Last Post: October 21st, 03:34 PM
  4. Replies: 0
    Last Post: September 15th, 12:08 AM
  5. note 33637 added to function.fprintf
    By Pilot@rack1.php.net in forum PHP Notes
    Replies: 0
    Last Post: July 2nd, 03:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •