Okay i found out what was happening....Thank you all for helping me! It is so much appreciated!
And another problem.
I'm reading from the txt file that says
and the program reads check no. but not sabre corporationCode:Check NO. Sabre Corporation 15790 West Henness Lane New Corio, New Mexico 65790
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); } }
How could that be.
Your code doesn't even compile
You're wasting our time.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);
Kurt
Last edited by ZuK; 05-17-2013 at 04:16 AM.
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.
Your code doesn't read anything at all. You forgot to post the relevant code.
Kurt
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.
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); } }
Since you didn't assign any values to 's' and 'c', what do you expect them to contain, but garbage?
Not in the code you just posted.I fscanf...
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:
That is what the output should look like.Code:* Sabre Corporation *
I wrote these lines of code:
All I am getting is garbageCode:fscanf(inputFILE, "%s%s", s, c)// scan file and find sabre corporation fprintf(inputFILE, COMPANYNAME, s, c) //COMPANYNAME contains the formatting "%s%s"
Can you post the updated code? It's a lot easier to help with something to reference.
Try to remain calm - you'll get nowhere good being frantic.I'm getting desperate.