Thread: fprintf

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    4

    fprintf

    Hi All,

    Just a quick question.

    I'm trying to print out a tabulated set of stock items.
    I've done most of it useing fprintf("%10s", item) etc
    but one part of the outputted line is an array e[i], which corresponds to an error message stored here. This line I can't seem to tab at the end of the line, it always seems to be at the beginning.

    Is there some problem with trying to do this or is there a way around it?

    Cheers

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    Can you post the code you have?
    It would make it easier for us to help you.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    4
    Sorry, derr me..


    void error(int i)
    {



    char *e[] = {"\nDigit Expected.",
    "\nNot a valid cc check digit.",
    "\nInvalid input.",
    "\nNot enough characters to be a valid customer name.",
    "\nInvalid record no first letter.",
    "\nInvalid address format, not enough fields." ,
    "\nMoney amount, digit expected.",
    "\nNot a valid Part code check digit."
    };
    if(lines>57)
    {
    /* new page needed for next record */
    /* form feed to new page */

    page++;
    fprintf(prn_ptr, "\nRembrandt's Paint Supplies plc\t\t\t\t\t\t\t\t\t %30.24s\t\t Page %d\n",asctime(todays_date),page);
    fprintf(prn_ptr, "\nRejected Transactions Report.");
    fprintf(prn_ptr, "\n\n\t\Record Type\tCustomer Code\tPart Number\tQuantity\tReason for Rejection\n");



    lines = 5;


    }


    fprintf(prn_ptr,"\n%5c ",transaction.ir.type);
    fprintf(prn_ptr,"%10s", transaction.ir.cust_code);
    if(transaction.create.type!='C')
    {
    fprintf(prn_ptr,"\t%10s\t%10s", transaction.ir.part_no,transaction.ir.quantity);

    }

    /*fwrite(e[i], strlen(e[i]),1, prn_ptr);*/
    fprintf(prn_ptr, "\t%6s",e[i]);

    /** the above line is the problem it always prints out at the left hand edge and I can't move it along the line */








    /* advance print for next record */
    lines = lines +1;

    /* set flag so that this record is not written to the validated file */
    delta =1;
    strcpy(prev_record, big);
    return; /*back to calling routine*/
    }


    Cheers

  4. #4
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    fprintf(prn_ptr, "\t%6s",e[i]);
    Try increasing the 6 to maybe 60, that will mean it prints it in a width of 60 spaces. Experiment until you find the right number. And using tabs can cause problems as the size of a tab can vary from machine to machine, best not to use them.
    Hope that solves it
    /*fwrite(e[i], strlen(e[i]),1, prn_ptr);*/
    fprintf(prn_ptr, "\t%6s",e[i]);
    whats the fwrite for, were you just experimenting

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    4
    I was using it to print at first, but tried a different way.
    Why would it be a better idea?

    Will try to play with the numbers.

    Cheers

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    4
    Nope, still prints the error from the array at the far left of the page.

    Any ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  3. sprintf and fprintf segmentation error
    By kona1 in forum C Programming
    Replies: 5
    Last Post: 06-21-2005, 10:55 AM
  4. fprintf to stderr crash programs
    By jlai in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2005, 08:51 AM
  5. fprintf
    By bennyandthejets in forum Windows Programming
    Replies: 10
    Last Post: 11-16-2002, 06:58 PM