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

    Join Date
    May 2013
    Rep Power

    Hi Have a question regarding formatting with getline and fprintf

    I have written a code that reads from a data file then onto the screen in the format of a check and takes the following lines; however, I am unable to get the proper formatting for the check that the assignment asks for. It should look like this.
    * Check NO *
    * Sabre Corporation *
    * 15790 West Henness Lane *
    * New Corio, New Mexico 65790 *
    * *
    but I'm getting this
    * *
    Sabre Corporation
    15790 West Henness Lane
    New Corio, New Mexico 65790
    void printReport(FILE **reportFILE, FILE **inputFILE);
    #define CHECK          "************************************************************\n" 
    #define CHECKBORDER    "*                                    Check No. %3d         *\n"
    #define CHECKFORMAT    "*                                                          *\n"
    #define COMPANYNAME    "*      %-6s%5s                                   *\n"
    #define COMPANYADDRESS "*      %-5d%5s %7s%5s                     *\n"
    #define CITYSTATE      "* %-6s%-2s*\n"
    #define CHECKFORMAT1   "*      Pay to the Order of                                 *\n"
    #define CHECKNAME      "*      %s                                        *\n"
    int main(void)
       char *line=NULL;
      char *line2=NULL;
      char *line3=NULL;
      size_t len=61;
      ssize_t bytes_read;
      FILE * inputFILE;
      printReport(&reportFILE, &inputFILE);
      fprintf(stdout, CHECK);//prints the top stars on screen for the check
      fprintf(stdout, CHECKFORMAT, number); //prints check no. 100
      bytes_read=getline(&line, &len, inputFILE);
       printf("%s", line);
      bytes_read=getline(&line2, &len, inputFILE);
       printf("%s", line2);
      bytes_read=getline(&line3, &len, inputFILE);
       printf("%s", line3);
      while(getchar()!= '\n');
      return 0;
    void printReport(FILE **reportFILE, FILE **inputFILE)
      if (*reportFILE==NULL)
        printf("Report File open failed...\n");
        exit(-80); //terminate app-reqs <stdlib.h>
        printf("File cannot be accessed");
    What can I do to reorganize the format so it prints the way it should?
  2. #2
  3. Contributing User

    Join Date
    Aug 2011
    Rep Power


    Searching for "number" shows one occurrence, and not in a declaration. The program doesn't compile under the syntax and lexical rules of c.
    $ gcc -Wall -g -c -o c.o c.c
    c.c: In function ‘main’:
    c.c:26:16: error: ‘reportFILE’ undeclared (first use in this function)
    c.c:26:16: note: each undeclared identifier is reported only once for each function it appears in
    c.c:29:32: error: ‘number’ undeclared (first use in this function)
    c.c:41:3: warning: statement with no effect [-Wunused-value]
    c.c:24:11: warning: variable ‘bytes_read’ set but not used [-Wunused-but-set-variable]
    Combining CHECKFORMAT with a variable first caught my attention. The CHECKFORMAT string doesn't have any specific % format specifiers.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo