Like Tree4Likes

Mysterious number is being printed.

This is a discussion on Mysterious number is being printed. within the C Programming forums, part of the General Programming Boards category; Originally Posted by arti the number that is supposed to go in there is 100 then increment to 105. Shouldn't ...

  1. #16
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by arti View Post
    the number that is supposed to go in there is 100 then increment to 105.
    Shouldn't you initialize it to 100 then ?
    Code:
    int number = 100;
    Kurt

  2. #17
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Okay i found out what was happening....Thank you all for helping me! It is so much appreciated!

  3. #18
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    And another problem.

    I'm reading from the txt file that says
    Code:
                                                Check NO.
        
    Sabre Corporation
    15790 West Henness Lane
    New Corio, New Mexico 65790
    and the program reads check no. but not sabre corporation

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    void printReport(FILE **reportFILE, FILE **inputFILE);
    
    #define CHECK         "************************************************************\n"
    #define CHECKBORDER   "*                                    Check No. %3d         *\n"
    #define CHECKFORMAT   "*                                                          *\n"
    #define COMPANYNAME   "*      %s%s                                                    *\n"
    
    #define CHECKFORMAT1  "*      Pay to the Order of                                 *\n"
    #define CHECKNAME     "*      %s                                        *\n"
    int main(void)
    {
        char S_name[12+10];
     
        char s[30];
        char c[30];
        FILE * inputFILE;
        printReport(&inputFILE);
    
    fprintf(stdout, CHECK);
      fprintf(stdout, CHECKBORDER, number);
      fprintf(stdout,CHECKFORMAT);
      fprintf(stdout, COMPANYNAME, s, c);
      
    
    
      //fprintf(stdout,CHECKFORMAT1);
      //fprintf(stdout,CHECKNAME, S_name);
      
      fclose(reportFILE);
     
    
      while(getchar()!= '\n');
      getchar;
      return 0;
    }
    
    void printReport(FILE **reportFILE, FILE **inputFILE)
    {
       *inputFILE=fopen("./check.txt","r");
      if(*inputFILE==NULL)
      { 
        printf("File cannot be accessed");
        exit(-80);
      }
    }

  4. #19
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by arti View Post
    and the program reads check no. but not sabre corporation
    How could that be.
    Your code doesn't even compile

    Code:
    chk.c: In function ‘main’:
    chk.c:20:5: error: too few arguments to function ‘printReport’
         printReport(&inputFILE);
         ^
    chk.c:4:6: note: declared here
     void printReport(FILE **reportFILE, FILE **inputFILE);
          ^
    chk.c:23:32: error: ‘number’ undeclared (first use in this function)
       fprintf(stdout, CHECKBORDER, number);
                                    ^
    chk.c:23:32: note: each undeclared identifier is reported only once for each function it appears in
    chk.c:32:10: error: ‘reportFILE’ undeclared (first use in this function)
       fclose(reportFILE);
    You're wasting our time.
    Kurt
    Last edited by ZuK; 05-17-2013 at 04:16 AM.
    AndiPersti likes this.

  5. #20
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by ZuK View Post
    How could that be.
    Your code doesn't even compile

    Code:
    chk.c: In function ‘main’:
    chk.c:20:5: error: too few arguments to function ‘printReport’
         printReport(&inputFILE);
         ^
    chk.c:4:6: note: declared here
     void printReport(FILE **reportFILE, FILE **inputFILE);
          ^
    chk.c:23:32: error: ‘number’ undeclared (first use in this function)
       fprintf(stdout, CHECKBORDER, number);
                                    ^
    chk.c:23:32: note: each undeclared identifier is reported only once for each function it appears in
    chk.c:32:10: error: ‘reportFILE’ undeclared (first use in this function)
       fclose(reportFILE);
    You're wasting our time.
    Kurt
    I am not wasting your time! This snippet of the code is from a bigger part of code which I have to take out so I don't have to post my entire code on the thread, which upon viewing what i posted i forgot to put the declaration for number which is an int set to 100 and also forgot to take out reportFILE because in this instance it is not being used.

  6. #21
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Your code doesn't read anything at all. You forgot to post the relevant code.
    Kurt

  7. #22
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by arti View Post
    I am not wasting your time! This snippet of the code is from a bigger part of code which I have to take out so I don't have to post my entire code on the thread, which upon viewing what i posted i forgot to put the declaration for number which is an int set to 100 and also forgot to take out reportFILE because in this instance it is not being used.
    So how about testing your code snippets before posting them?

    Bye, Andreas

  8. #23
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by AndiPersti View Post
    So how about testing your code snippets before posting them?

    Bye, Andreas
    Thank you for your advice. Here is the code that I'm having problems with. I followed the code that my tutor suggested i use and it is printing out garbage.
    Name:  Screenshot from 2013-05-17 15:08:55.jpg
Views: 52
Size:  51.3 KB

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    void printReport(FILE **inputFILE);
     
    #define CHECK         "************************************************************\n"
    #define CHECKBORDER   "*                                    Check No. %3d         *\n"
    #define CHECKFORMAT   "*                                                          *\n"
    #define COMPANYNAME   "*      %s%s                                                    *\n"
     
    #define CHECKFORMAT1  "*      Pay to the Order of                                 *\n"
    #define CHECKNAME     "*      %s                                        *\n"
    int main(void)
    {
        char S_name[12+10];
        int number=100;  
        char s[30];
        char c[30];
        FILE * inputFILE;
        printReport(&inputFILE);
     
    fprintf(stdout, CHECK);
      fprintf(stdout, CHECKBORDER, number);
      fprintf(stdout,CHECKFORMAT);
      fprintf(stdout, COMPANYNAME, s, c);
       
     
     
      //fprintf(stdout,CHECKFORMAT1);
      //fprintf(stdout,CHECKNAME, S_name);
       
      fclose(inputFILE);
      
     
      while(getchar()!= '\n');
      getchar;
      return 0;
    }
     
    void printReport(FILE **inputFILE)
    {
       *inputFILE=fopen("./check.data","r");
      if(*inputFILE==NULL)
      { 
        printf("File cannot be accessed");
        exit(-80);
      }
    }

  9. #24
    Registered User
    Join Date
    Jun 2011
    Posts
    2,569
    Since you didn't assign any values to 's' and 'c', what do you expect them to contain, but garbage?

  10. #25
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by Matticus View Post
    Since you didn't assign any values to 's' and 'c', what do you expect them to contain, but garbage?
    I'm reading ffrom the file check.data which then is supposed to print to the screen the name Sabre Corporation which is in the file. I fscanf then I fprintf so i could read then print but it's not working.

  11. #26
    Registered User
    Join Date
    Jun 2011
    Posts
    2,569
    I fscanf...
    Not in the code you just posted.

  12. #27
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by Matticus View Post
    Not in the code you just posted.

    I used fscanf and fprintf before and it worked but now it isn't. I'm currently using it and it's not working. I also USED the getline function but that's not working at all either.

  13. #28
    Registered User
    Join Date
    Jun 2011
    Posts
    2,569
    Quote Originally Posted by arti View Post
    I used fscanf and fprintf before and it worked but now it isn't. I'm currently using it and it's not working. I also USED the getline function but that's not working at all either.
    I haven't been following this thread, I just made an observation on the latest code you posted, so I apologize if I'm not understand you here.

    In the latest code you posted, post #23, you are not scanning anything, anywhere. So on the output you show in the screen shot in the same post is showing garbage being printed.

    If it was a previous version of the code that had "fscanf()" calls, then that's irrelevant to your post #23 which contains, it appears, the latest version of the code and the resulting output.
    ZuK and AndiPersti like this.

  14. #29
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by Matticus View Post
    I haven't been following this thread, I just made an observation on the latest code you posted, so I apologize if I'm not understand you here.

    In the latest code you posted, post #23, you are not scanning anything, anywhere. So on the output you show in the screen shot in the same post is showing garbage being printed.

    If it was a previous version of the code that had "fscanf()" calls, then that's irrelevant to your post #23 which contains, it appears, the latest version of the code and the resulting output.
    True. Sorry about that. I'm getting desperate. I used fscanf and fprintf before posting here and it worked fine....since now I have to format the check with stars it is not working:
    Code:
    *         Sabre Corporation                                   *
    That is what the output should look like.
    I wrote these lines of code:
    Code:
    fscanf(inputFILE, "%s%s", s, c)// scan file and find sabre corporation
    fprintf(inputFILE, COMPANYNAME, s, c) //COMPANYNAME contains the formatting "%s%s"
    All I am getting is garbage

  15. #30
    Registered User
    Join Date
    Jun 2011
    Posts
    2,569
    Can you post the updated code? It's a lot easier to help with something to reference.

    I'm getting desperate.
    Try to remain calm - you'll get nowhere good being frantic.

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mysterious seg fault!
    By MK27 in forum C++ Programming
    Replies: 12
    Last Post: 03-12-2010, 01:29 AM
  2. Getting a bmp copy of what i printed
    By knutso in forum Windows Programming
    Replies: 6
    Last Post: 04-16-2007, 05:29 AM
  3. int wrong value being printed?
    By Axel in forum C Programming
    Replies: 11
    Last Post: 10-14-2006, 01:37 AM
  4. Getting number of pages printed
    By Yasir_Malik in forum Linux Programming
    Replies: 2
    Last Post: 09-21-2004, 02:59 PM
  5. mysterious code.......(??)
    By deltabird in forum C Programming
    Replies: 7
    Last Post: 04-11-2003, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21